Android:视频视图:如何循环播放视频 [英] Android: Video View: how to play a video on a loop
问题描述
我有一个简单的对话框,其中包含VideoView
,我想循环播放视频.
I got a simple dialog box with a VideoView
in it and I want to play the video in a loop.
我当前正在使用快速修复程序
I'm currently using a quick fix
//Video Loop
vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
vv.start();
}
});
但是我想知道是否有更好的方法?
but I would like to know if there is a better way?
修改
我要添加更多代码,因为我不知道如何通过VideoView
访问MediaPlayer对象:
I'm adding more code because I don't know how I can get access to the MediaPlayer object form the VideoView
:
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
bu,我想知道是否可以直接使用VideoView
I'm currently looking into using directly MediaPlayer
and a SurfaceView
bu I would like to know if there is a way with VideoView
directly
推荐答案
使用您的MediaPlayer实例上的setLooping(true).
-编辑-
如何改用 setOnPrepareListener setOnCompletionListener的?这使您可以访问MediaPlayer对象.
How about using setOnPrepareListener instead of setOnCompletionListener? This gives you access to the MediaPlayer object.
vv.setOnPreparedListener (new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
这篇关于Android:视频视图:如何循环播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!