【发布时间】:2011-01-29 09:49:51
【问题描述】:
我正在做多媒体应用程序。我尝试了几个不同的示例来在表面视图中实现视频,但我无法获得。我能听到声音,但没有出现视觉。有没有可能在表面视图中获得视频。我的目标 SDK 是 2.2 API 级别 8。即使我将我的 apk 安装到移动设备上,仍然没有任何改变。请指导我。
【问题讨论】:
标签: android video surfaceview
我正在做多媒体应用程序。我尝试了几个不同的示例来在表面视图中实现视频,但我无法获得。我能听到声音,但没有出现视觉。有没有可能在表面视图中获得视频。我的目标 SDK 是 2.2 API 级别 8。即使我将我的 apk 安装到移动设备上,仍然没有任何改变。请指导我。
【问题讨论】:
标签: android video surfaceview
我不确定您想如何播放视频、流式传输或将其复制到您的 SD 卡或 /res 文件夹中,但我有以下播放视频的方法。我可以选择是流式传输还是从 sdcard 上的文件夹播放
视频.java
import android.app.Activity;
import android.os.Bundle;
import android.widget.VideoView;
public class Movie extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_layout);
VideoView video = (VideoView) findViewById(R.id.movie);
//this is the place where you define where to get the video from (this can be from your sd or a stream)
video.setVideoPath(
"/sdcard/video/videofile.mp4"
/*"rtsp://Youtube Stream*/
);
//after the video is loaded it will then start
video.start();
}
}
video_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<VideoView
android:id="@+id/movie"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center">
</VideoView>
</FrameLayout>
希望对您有所帮助! SurfaceView 也有一些问题,但这样我的问题就解决了。
【讨论】: