晚上好,我有以下问题。我想在VideoView中播放视频格式* .3gp。我尝试使用此代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylay);
VideoView videoHolder = new VideoView(this);
videoHolder = (VideoView) findViewById(R.id.videoView1);
Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.asd);
videoHolder.setVideoURI(video);
videoHolder.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mp.start();
mp.setLooping(true);
}
});
}
仿真器和HTC Desire S.一切正常。但是有一款中文平板电脑昂达V972,每次都会给我一个“播放视频时出错”:
06-19 18:34:18.890: W/AudioSystem(25145): AudioFlinger server died!
06-19 18:34:18.890: W/IMediaDeathNotifier(25145): media server died
06-19 18:34:18.890: E/MediaPlayer(25145): error (100, 0)
06-19 18:34:18.890: E/MediaPlayer(25145): Error (100,0)
06-19 18:34:18.890: D/VideoView(25145): Error: 100,0
请告诉我这个问题是否可以解决。非常感谢。也许还有另一种方法可以将视频文件加载到VideoView中?
更新21.06:
刚刚更新了平板电脑的固件,现在视频正在播放但没有循环播放。我已经尝试了以下代码,但rusult是相同的 - HTC和模拟器做得很好,但平板电脑不循环视频。我也试过* .mp4,都是这样的:
VideoView videoHolder = new VideoView(this);
videoHolder = (VideoView) findViewById(R.id.videoView1);
// videoHolder.setMediaController(new MediaController(this));
Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.asd);
videoHolder.setVideoURI(video);
// setContentView(videoHolder);
videoHolder.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
mp.start();
}
});
videoHolder
.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.mp.seekTo(0);
mp.start();
}
});
问题是 - 如何在所有设备上制作视频?
答案 0 :(得分:0)
尝试使用媒体控制器设置的视频集
public class HelloInterruptVideoStream extends Activity
{
private String path = "http://dl.dropbox.com/u/145894/t/rabbits.3gp";
private VideoView videoview;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
videoview = (VideoView)findViewById(R.id.surface_view);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
videoview.setVideoURI(Uri.parse(path));
videoview.setMediaController(new MediaController(this));
videoview.requestFocus();
videoview.start();
}
}