视频不循环 Android VideoView [英] Video doesn't loop Android VideoView

查看:35
本文介绍了视频不循环 Android VideoView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个可以循环播放视频的 Android 应用程序!问题是它永远不会循环!它只播放一次视频!在调试期间,我意识到正在执行myVideoView.setOnCompletionListener"但视频不播放!我也在 CompletionListener 中尝试mp.reset()".也许我遗漏了其他文件中的某些内容,例如清单?

I am trying to build an android app that will loop a video! The problem is that it never loops! It plays the video only once! During debugging i realized that the "myVideoView.setOnCompletionListener" is being executed but the video doesn't play! I also try "mp.reset()" inside the CompletionListener. Maybe i am missing something in a different file, such as the Manifest?

有什么想法吗?这是我的代码:

Any thoughts? Here is my code:

  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));

           }
        });

推荐答案

尝试 onPreparedListener 而不是 onCompletionListener:

myVideoView.setOnPreparedListener(new OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.setLooping(true);
    }
});

希望这会有所帮助.

这篇关于视频不循环 Android VideoView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆