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

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值