我有一个简单的对话框,里面有一个 VideoView
,我想循环播放视频。
我目前正在使用快速修复
//Video Loop
vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
vv.start();
}
});
但我想知道是否有更好的方法?
编辑
我正在添加更多代码,因为我不知道如何从 VideoView
访问 MediaPlayer 对象:
String path = defaultPath+currentVideoRessource;
if (path == null || path.length() == 0) {
Log.e("extra","File URL/path is empty");
} else {
// If the path has not changed, just start the media player
if (!path.equals(current) && mVideoView != null) {
Uri pathURI = Uri.parse(defaultPath+currentVideoRessource);
mVideoView.setVideoURI(pathURI);
}
current = path;
mVideoView.setOnCompletionListener(new MyOnCompletionListener(this));
//Video Loop
// mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
// public void onCompletion(MediaPlayer mp) {
// mVideoView.start(); //need to make transition seamless.
// }
// });
mVideoView.start();
mVideoView.requestFocus();
我目前正在研究直接使用 MediaPlayer
和 SurfaceView
但我想知道是否有直接使用 VideoView
的方法
最佳答案
使用 setLooping(true)在您的 MediaPlayer 实例上。
--编辑--
如何使用setOnPrepareListener而不是 setOnCompletionListener?这使您可以访问 MediaPlayer 对象。
vv.setOnPreparedListener (new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
关于Android:视频 View :如何循环播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5569631/