Android MediaPlayer播放异常问题汇总

一、关于 “MediaPlayer error (XXXX,XXXX) 

问题1:

E/MediaPlayer(19765): stop called in state 4
E/MediaPlayer(19765): error (-38, 0)

原因:是在调用prepareAsync()则以异步方式进入Prepared状态过程中即preparing状态中,调用了stop方法。

参考:http://stackoverflow.com/questions/8796956/mediaplayer-stop-called-in-state-4

问题2:

Media Player called in state 0, error (-38,0)

原因是在You're using prepareAsync, which is asynchronous. That is, you should wait for the onPrepared callback before you do anything that relies on the preparation to be complete (like calling start). That's why you get the "start called in state 4" error message (state 4 is MEDIA_PLAYER_PREPARING).

即调用 prepareAsync,在preparing过程中调用了start。

参考:http://stackoverflow.com/questions/16495276/mediaplayer-track-change-issue 

问题3:

Attempt to call getDuration without a valid mediaplayer in media player on android

原因:在preparing过程中调用了getDuration方法。

You might be calling getDuration before the file is fully loaded.

参考:http://stackoverflow.com/questions/6026288/attempt-to-call-getduration-without-a-valid-mediaplayer-in-media-player-on-andr 

问题4:如果你使用VideoView播放过MP4视频,你可能碰到过类似下面的问题:

MediaPlayer error (1, -2147483648)

如果你查阅文档,会发现1其实代表MEDIA_ERROR_UNKNOWN,不过文档对-2147483648(0x80000000)没有做什么说明,实际上它也是代表unknown error的意思。

真正的原因在于,MP4有多种编码格式,例如H.264,H.263等,而android版本较低的机器只支持部分编码。

一旦遭遇不被支持的编码格式,MediaPlayer可能就会抛出上面的错误信息。

如果你也遇到这类问题,你可以使用一些视频软件查看视频的编码格式,然后转换为普遍支持的格式。

stackoverflow上有关于此问题的讨论,下面是一些链接:

http://stackoverflow.com/questions/10849044/cant-play-mp4-video-in-my-android-app

http://superuser.com/questions/371460/command-encoding-h264-baseline-profile-level-1-with-ffmpeg-and-libx264

http://stackoverflow.com/questions/11540076/android-mediaplayer-error-1-2147483648

http://developer.android.com/guide/appendix/media-formats.html

你可能感兴趣的:(Android)