4

我正在尝试构建一个可以循环播放视频的 android 应用程序!问题是它永远不会循环!它只播放一次视频!在调试过程中,我意识到“myVideoView.setOnCompletionListener”正在执行,但视频没有播放!我还在 CompletionListener 中尝试了“mp.reset()”。也许我在不同的文件中遗漏了一些东西,比如清单?

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

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

           }
        });
4

3 回答 3

15

尝试onPreparedListener代替onCompletionListener

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

希望这可以帮助。

于 2012-11-15T12:01:53.777 回答
7

尝试这个。

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

    }
});

由您的视频完成后重新开始...

于 2013-07-05T06:05:42.550 回答
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();

                }
            });
于 2019-07-16T04:28:13.217 回答