Android:视频 View :如何循环播放视频

标签 android video android-videoview

我有一个简单的对话框,里面有一个 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();

我目前正在研究直接使用 MediaPlayerSurfaceView 但我想知道是否有直接使用 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/

相关文章:

android - Firebase 电话验证 verifyPhoneNumber() 已弃用 + 应用程序崩溃

nginx - 使用 FFMPEG 将 RTMP 源重新流式传输到 YouTube - 输出中没有视频流

video - FFMPEG Image2pipe 生成损坏的视频

javascript - 如何在chrome浏览器中播放本地视频文件?

android - 获取 Uri Android 的真实路径

android - DayDream 中的 VideoView 和 MediaController?

android - 如何更改 Aviary for Android 给出的裁剪效果的顺序

android - android设备有多少种扬声器?

Android 主屏幕小部件(图标、标签 - 样式)

java - VideoView 在通过套接字接收文件时播放文件