视频视图/媒体播放器错误(1、-18)

发布于 2024-12-07 04:58:44 字数 1986 浏览 1 评论 0原文

我有一个按照 API 级别 2.2 构建的应用程序。该应用程序包含一个启动后立即开始播放的视频。视频在 VideoView 内播放,实际视频文件存储在我的内部存储中(我的应用程序包的文件目录)。

大多数时候它启动得很好。但有时我会弹出一个错误消息,显示“抱歉,该视频无法播放”。并有一个“确定”按钮。一旦我按下“确定”按钮,视频就会开始正确播放。我需要找出导致此错误的原因,或者至少如何捕获它是什么错误并重试,因为在我点击“确定”后它总是完美运行。当显示此错误框时,在日志中我会看到以下消息:

 ERROR/PVOMXAudDecNode(21215): Ln 2232 OMX_EventError nData1 -2147479547 nData2 0
 ERROR/PlayerDriver(21215): Command PLAYER_PREPARE completed with an error or info -18
 ERROR/MediaPlayer(9282): message received msg=100, ext1=1, ext2=-18
 ERROR/MediaPlayer(9282): error (1, -18)
 ERROR/MediaPlayer(9282): callback application
 ERROR/MediaPlayer(9282): back from callback
 ERROR/MediaPlayer(9282): Error (1,-18)
 DEBUG/VideoView(9282): Error: 1,-18

在哪里可以找到有关错误代码 -18 究竟表示什么的参考?有没有人有任何建议我可以尝试从一开始就防止这种情况发生。我只在 Sprint Epic 4g 上观察到此错误。

编辑:据我所知,没有任何异常发生。我假设正在发生的事情是视频视图知道捕获引起的任何异常并抛出弹出窗口。在我的日志中,没有异常堆栈跟踪,只有对错误 -18 的引用。

至于我如何调用prepare。我使用这个:

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

和这个:

mVideoView.setVideoPath(file.getAbsolutePath());

它调用prepare作为setVideoPath的一部分(我认为它无论如何都会这样做,但这个方法没有记录)。这会导致 onPrepared 在我的监听器中被调用。

编辑2:现在我刚刚添加了一个onErrorListener,如下所示:

编辑重要!此代码将在 ICS 上无限错误循环。对于 ICS 设备,我取出了 setPath 调用,并返回 false。它会自行再次尝试一次并成功。

    mVideoView.setOnErrorListener(new OnErrorListener(){

        @Override
        public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
            Log.i(myTag, "MP ERROR: "+ arg1 + " - " + arg2);
            mVideoView.setVideoPath(file.getAbsolutePath());
            return true;
        }

    });

这会捕获错误,并且当此错误发生时我可以在日志中看到 arg2 = -18。我只是让它重试并返回 true,这样它就不会弹出对话框。到目前为止,我从未见过它连续两次失败,所以这总是正确启动视频并且不会无限循环。

如果有人能准确地告诉我错误代码 -18 表示什么,我仍然非常感兴趣。

I have an application that is built to API level 2.2. This application contains a video that starts playing as soon as it is launched. The video is played inside a VideoView and the actually video file is stored in my internal storage (files directory for my apps package).

Most of the time it starts up just fine. But occasionally I get an error pop - up that says "Sorry, this video cannot be played." and has an Ok button. As soon as I press the ok button the video starts playing correctly. I need to figure out what is causing this error, or at the very least how I can catch whatever error it is and have it try again since it always works perfect after I hit ok. Inside the logs when this error box is shown I see these messages:

 ERROR/PVOMXAudDecNode(21215): Ln 2232 OMX_EventError nData1 -2147479547 nData2 0
 ERROR/PlayerDriver(21215): Command PLAYER_PREPARE completed with an error or info -18
 ERROR/MediaPlayer(9282): message received msg=100, ext1=1, ext2=-18
 ERROR/MediaPlayer(9282): error (1, -18)
 ERROR/MediaPlayer(9282): callback application
 ERROR/MediaPlayer(9282): back from callback
 ERROR/MediaPlayer(9282): Error (1,-18)
 DEBUG/VideoView(9282): Error: 1,-18

Where can I find a reference as to what exactly error code -18 indicates? And does anyone have any suggestions I could try to prevent it from happening in the first place. I have only observed This error on the Sprint Epic 4g.

Edit: well as far as I can tell no exceptions are getting thrown to me. I assume what is happening is that the video view knows to catch whatever exception is causing and it throws up the pop-up. Inside my log there is no exception stack trace just this reference to error -18.

As for how I am calling prepare. I use this:

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

and this:

mVideoView.setVideoPath(file.getAbsolutePath());

it calls prepare as part of setVideoPath (I assume it does anyway, but this method is undocumented). which causes onPrepared to get called in my listener.

Edit 2: for now i've just added an onErrorListener like so:

EDIT IMORTANT! this code will infinte error loop on ICS. For ICS devices I took out the setPath call, and returned false instead. It tries again by itself once and it succeeds.

    mVideoView.setOnErrorListener(new OnErrorListener(){

        @Override
        public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
            Log.i(myTag, "MP ERROR: "+ arg1 + " - " + arg2);
            mVideoView.setVideoPath(file.getAbsolutePath());
            return true;
        }

    });

this catches the error and I can see in my logs that arg2 = -18 when this error happens. I just have it retry and return true so it doesn't throw up the dialog. So far i've never seen it fail twice in a row so this always starts the video correctly and doesn't make infinite loop.

I am still very interested if anyone can tell me exactly what error code -18 indicates though.

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

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

发布评论

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

评论(2

挽容 2024-12-14 04:58:45

如何捕获 prepare() 抛出的潜在异常?您是否专门捕获IOException,然后重试调用prepare()

尝试使用 prepareAsync() 代替,它不会阻塞并在播放器准备好时调用侦听器。而且它不会抛出IOException

How do you catch potential exceptions thrown by prepare()? Do you catch IOException specifically and then retry calling the prepare()?

Try using prepareAsync() instead, which does not block and calls listener when player is ready. Also it does not throw IOException.

倒带 2024-12-14 04:58:45

如果您在 Froyo 或 Gingerbread 上运行它,问题可能是您的设备不支持文件播放。较低版本不支持使用基线格式以外的格式编码的视频。您可以使用一些工具(例如电脑上的视频信息)检查文件是否为基线格式。

If you are running it on Froyo or Gingerbread the problem might be your device is not supporting playback of the file. Lower versions do not support videos encoded with formats other than baseline format. You may use some tools like video info on pc and check if the files are baseline formatted.

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