VideoView循环播放视频 补充

发布于 2024-11-29 00:33:47 字数 2173 浏览 0 评论 0原文

我有一个带有 VideoView 的应用程序,它将不断循环播放相同的视频,直到用户对设备(触摸屏等)执行某些操作。目前,我正在使用 OnCompletionListener() 在视频结束后重新启动视频。这在我测试过的所有设备上都能正常工作,除了 Samsung Replenish。

这是我的代码:

    mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        public void onCompletion(MediaPlayer mp) {
            mVideoView.setVideoPath(file.getAbsolutePath());
            mVideoView.start();
        }
    });

“补充”时发生的情况是视频一直播放一次,但随后再也不会开始,并且屏幕全黑(但背光仍然打开)。在我用完全相同的代码测试过的所有其他设备上,它都可以重复播放视频。有谁知道有关补货的任何具体信息可能会导致此错误?我想也许将对 setVideoPath() 和 start() 的调用延迟 200-300 毫秒可能会有所帮助,但这没有任何影响。我在这里真的很茫然。

我在我的日志中看到这些消息:

错误/QCvdec(87):vdec 尚未初始化时发出 Omx Flush。

错误/QCvdec(87):OMXCORE-SM:收到命令禁用 (2)

错误/QCvdec(87):vdec 尚未初始化时发出 Omx Flush。

错误/QCvdec(87):OMXCORE-SM:收到命令启用 (3)

但是这些日志在视频启动(第一次播放)和无法再次启动时都会发生。所以我不确定它们是否与我的问题有关

编辑:

我只是尝试将 mVideoView 设置为 null,然后在 setVideoPath() 之前使用 findViewById() 获取对它的新引用。我知道这会使 OnCompletionListener 的设置方式变得复杂。但无论如何它都不起作用,仍然是同样的黑屏。

编辑 2:

我开始注意到有时视频甚至无法第一次启动。我第一次使用同样的两行来启动它:

        mVideoView.setVideoPath(file.getAbsolutePath());
        mVideoView.start();

它似乎启动更一致,但第一次播放时不是 100%。

编辑3:这就是我现在的设置方式。我正在手动设置 OnPreparedListener 来为我启动视频。所以我将其添加到我的 onCreate() 中,

        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        
            @Override
            public void onPrepared(MediaPlayer arg0) {
                 mVideoView.start();
            }
        });

然后当我准备重新启动视频时,我只调用 setVideoPath() 方法,如下所示:

mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
    public void onCompletion(MediaPlayer mp) {
        mVideoView.setVideoPath(file.getAbsolutePath());
        
    }
});

这似乎可以解决问题。不过,我让它运行一段时间才能确定。

编辑4:

@MByD 在VideoView setVideoPath() 的代码中是setVideoUri() 的包装。 setVideoURI() 正在设置 mStartWhenPrepared = false; 默认的 OnPreparedListener 会检查此开关来决定是否开始播放。这就是为什么它不以默认侦听器启动的原因。我没有对此进行更多研究,但可能有一个 setter 方法可以让我将 mStartWhenPrepared 值更改为 true,这将导致视频从默认侦听器启动。

I have an application with a VideoView that will keep looping the same video over and over until a user does something to the device(touch screen, etc) Currently I am using the OnCompletionListener() to restart the video once it ends. This works properly on every device I have tested, except for the Samsung Replenish.

Here is my code:

    mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        public void onCompletion(MediaPlayer mp) {
            mVideoView.setVideoPath(file.getAbsolutePath());
            mVideoView.start();
        }
    });

What happens on the Replenish is the video plays all the way through once but then is never started again and the screen goes all black (But backlight still turned on). On every other device I've tested on with this exact same code it has worked to repeat the video. Does anyone know of anything specific about the Replenish that could cause this error? I thought maybe delaying the calls to setVideoPath(), and start() by 200-300ms might help it, but that had no affect. I am really at a loss here.

I am seeing these messages in my Log:

ERROR/QCvdec(87): Omx Flush issued when vdec is not initialized yet.

ERROR/QCvdec(87): OMXCORE-SM:Recieved command DISABLE (2)

ERROR/QCvdec(87): Omx Flush issued when vdec is not initialized yet.

ERROR/QCvdec(87): OMXCORE-SM:Recieved command ENABLE (3)

But these logs are happening both when the video starts (the first time it plays) and when it fails to start again. so I am not sure if they are related to my problem

Edit:

I just tried setting mVideoView to null, and then getting a new reference to it with findViewById() right before the setVideoPath(). I know this would complicate the way the OnCompletionListener is set up. But regardless of that it didn't work anyway, still the same dark screen.

Edit 2:

I've started to notice that sometimes the video doesn't even start the first time. I am using these same two lines to start it up the first time:

        mVideoView.setVideoPath(file.getAbsolutePath());
        mVideoView.start();

It seems to start more consistantly, but not quite 100% when its the first time it is being played.

Edit 3: This is how I have it set up now. I am manually setting the OnPreparedListener to start the video for me. So I added this to my onCreate()

        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        
            @Override
            public void onPrepared(MediaPlayer arg0) {
                 mVideoView.start();
            }
        });

Then when I am ready to restart the video I just call only the setVideoPath() method, Like this:

mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
    public void onCompletion(MediaPlayer mp) {
        mVideoView.setVideoPath(file.getAbsolutePath());
        
    }
});

This seems to be doing the trick. I am letting it run for a while to find out for sure though.

Edit 4:

@MByD In the code for VideoView setVideoPath() is a wrapper for setVideoUri(). setVideoURI() is setting mStartWhenPrepared = false; The default OnPreparedListener checks this switch to decide whether to start playback or not. That is why it doesn't start with the default listener. I haven't looked into it more than that, but there may be a setter method that lets me change the mStartWhenPrepared value to true, which would cause the video to be started from the default listener.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野生奥特曼 2024-12-06 00:33:47

您是否尝试过在调用 .start() 之前准备好您的视频?

来自文档: http://developer.android.com /reference/android/media/MediaPlayer.html#prepare%28%29

带有 OnPreparedListener 您可以在视频准备好后开始播放。

Have you tryed to prepare() your video before you call .start()?

from the docs: http://developer.android.com/reference/android/media/MediaPlayer.html#prepare%28%29

with a OnPreparedListener you can start your video when its ready.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文