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就可以了.
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就可以了.
相关文章推荐
- android错误之MediaPlayer用法的Media Player called in state *,androidmediaplayer
- android错误之MediaPlayer用法的Media Player called in state *
- Android MediaPlayer 播放prepareAsync called in state 8解决办法
- android错误之MediaPlayer用法的Media Player called in state *
- Android MediaPlayer播放prepareAsync called in state 8解决办法
- 【Android】- MediaPlayer错误之MediaPlayer start called in state 0
- Android(java)学习笔记180:Android MediaPlayer 播放prepareAsync called in state 8解决办法
- Android MediaPlayer播放prepareAsync called in state 8解决办法
- Mediaplayer播放资源文件遇到的问题prepareAsync called in state 8
- Android MediaPlayer 播放prepareAsync called in state 8解决办法
- 实习入职第九天---android错误之MediaPlayer用法的Media Player called in state *
- E/MediaPlayer(18731): prepareAsync called in state 8和MediaPlayer返回值是NULL;
- Android MediaPlayer播放prepareAsync called in state 8解决办法 分类: Android多媒体 2015-01-08 10:16 54人阅读 评论(0) 收藏
- MediaPlayer: start called in state 0报错处理
- android 播放器遇到prepareAsync called in state 8
- 错误信息:setDataSource is called in state
- 音乐Visualizer类的错误 setCaptureSize() called in wrong state: 2 的解决办法
- Android初学------“prepareAsync called in state 8 ”解决办法
- media player prepareAsync called in state 8
- prepareAsync called in state 1