MediaPlayer报错prepareAsync called in state 8

简介: 错误总结: MediaPlayer报错prepareAsync called in state 8 原因: 在进入Activity后在Oncreate()方法中: mMediaPlayer=MediaPlayer.

错误总结:
MediaPlayer报错prepareAsync called in state 8


原因:
在进入Activity后在Oncreate()方法中:
mMediaPlayer=MediaPlayer.create(MainActivity.this, R.raw.big);
为此mMediaPlayer设置了要播放的资源
但是在点击stop按钮以后,执行了mMediaPlayer.release();
这样的话就释放了资源.所以再次点击播放的时候报错

解决办法:
在每次点击play的时候,都执行MediaPlayer.create()

注意:
可以在每次点击暂停的时候保存现在播放的位置即:
position=mMediaPlayer.getCurrentPosition();
然后在每次播放的时候
mMediaPlayer.seekTo(position);
这样就会从暂停处继续播放

相关文章
|
7月前
|
NoSQL 编译器 API
关于thread使用的错误:pure virtual method called terminate called without an active exception
关于thread使用的错误:pure virtual method called terminate called without an active exception
146 1
已解决 RuntimeError: There is no current event loop in thread ‘Thread-1‘.
Jetson Xavier NX 报错 RuntimeError: There is no current event loop in thread 'Thread-1'.异常错误,已解决
604 0
已解决 RuntimeError: There is no current event loop in thread ‘Thread-1‘.
|
开发工具 Android开发
解决bug:运行项目时报异常 “Can't create handler inside thread that has not called Looper.prepare()”
解决bug:运行项目时报异常 “Can't create handler inside thread that has not called Looper.prepare()”
1260 0
|
7月前
|
开发工具 git
解决pre-commit hook failed (add --no-verify to bypass)的问题
该文介绍了两种免去Git预提交钩子(pre-commit)的方法。一是直接进入项目.git/hooks目录,使用`rm -rf ./git/hooks/pre-commit`命令删除pre-commit文件。二是提交时添加`--no-verify`参数,如`git commit --no-verify -m"XXX"`,以跳过预提交检查。
294 0
|
7月前
|
TensorFlow 算法框架/工具 Python
完美解决丨RuntimeError: create_session() called before __init__().
完美解决丨RuntimeError: create_session() called before __init__().
|
Android开发
Android MediaPlayer 播放prepareAsync called in state 8解决办法
Android MediaPlayer 播放prepareAsync called in state 8解决办法
274 0