您的位置:首页 > 其它

MediaPlayer 的prepareAsync called in state 8 错误

2014-06-02 16:27 357 查看
注:本文转自

http://hi.baidu.com/ghostlitao/item/9fb189f97015996a3c148500,所有权利归原作者所有

在抄网上的一个例子,但是发现运行的各种出错,纠结.
prepareAsync called in state

prepare 同步出错?
那说明已经prepare已经被调用了,为什么呢?

m = MediaPlayer.create(this, R.raw.sky);// 设置mediaPlayer播放源

很有可能,你是通过create方式创建的播放器,所以我们看下create的源码吧:
//================================create源码开始=========================/

public static MediaPlayer create(Context context, int resid) {
try {
AssetFileDescriptor afd = context.getResources().openRawResourceFd(resid);
if (afd == null) return null;

MediaPlayer mp = new MediaPlayer();
mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
afd.close();
mp.prepare();
return mp;
} catch (IOException ex) {
Log.d(TAG, "create failed:", ex);
// fall through
} catch (IllegalArgumentException ex) {
Log.d(TAG, "create failed:", ex);
// fall through
} catch (SecurityException ex) {
Log.d(TAG, "create failed:", ex);
// fall through
}
return null;
}
//================================create源码结束开始=========================/

注意红色部分,懂了吧?
因为create方法已经帮你prepare了,所以你只需要start就可以了.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: