我正在尝试构建一个可以循环播放视频的Android应用! 问题是它永远不会循环!它只播放一次视频! 在调试过程中,我意识到“myVideoView.setOnCompletionListener”正在执行,但视频无法播放! 我还在CompletionListener中尝试“mp.reset()”。 也许我错过了一个不同的文件,比如Manifest?
有什么想法? 这是我的代码:
final VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
myVideoView.setVideoURI(Uri.parse(SrcPath));
myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer arg0) {
myVideoView.requestFocus();
myVideoView.start();
}
});
myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
myVideoView.setVideoURI(Uri.parse(SrcPath));
}
});
答案 0 :(得分:14)
尝试使用onPreparedListener
代替onCompletionListener
:
myVideoView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
希望这有帮助。
答案 1 :(得分:6)
试试这个。
myVideoView = (VideoView) findViewById(R.id.videoView1);
myVideoView.setVideoPath(video_path);
myVideoView.setMediaController(new MediaController(this));
myVideoView.start();
myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
myVideoView.start();
}
});
完成视频后再次启动...
答案 2 :(得分:0)
尝试一下。
videoView.setVideoPath(tempFileMessageUri.toString());
ctlr = new MediaController(context);
ctlr.setMediaPlayer(videoView);
videoView.setMediaController(ctlr);
videoView.requestFocus();
videoView.start();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
videoView.start();
}
});
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
videoView.start();
}
});