开发者

VideoView / MediaPlayer Error (1, -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 onE开发者_Python百科rrorListener 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜