Android 媒体播放器返回 IllegalStateException
我有以下代码来播放小音频文件
private void playVoice() {
if (mPlayVoice != null) {
if (mPlayVoice.isPlaying()) {
mPlayVoice.release();
mPlayVoice = null;
}
}
mPlayVoice =
MediaPlayer.create(BirdsActivity.this, mSoundIds[getCurrentIndex()]);
mPlayVoice.start();
}
它在三星 Galaxy 选项卡中工作正常,但在小型设备中给出以下错误(我在索尼 xperia mini pro 中检查了我的项目)
08-17 12:45:45.232: ERROR/AndroidRuntime(6639): java.lang.IllegalStateException
08-17 12:45:45.232: ERROR/AndroidRuntime(6639): at android.media.MediaPlayer.isPlaying(Native Method)
08-17 12:45:45.232: ERROR/AndroidRuntime(6639): at com.android.mds.kidsapps.alphakids.BirdsActivity.playVoice(BirdsActivity.java:146)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你正在这样做:
你不是说
如果你有其他问题,这是最好的参考文档:
Android MediaPlayer
编辑
好的,如果您在这里:isPlaying() 无效状态 它表明您正在尝试在播放器处于错误状态时调用 isPlaying()。因此,您需要弄清楚为什么它已经处于错误状态。
看看添加错误侦听器:
You're doing this:
Do you not mean
If you have other issues this is the best document to consult:
Android MediaPlayer
EDIT
Ok if you are here: isPlaying() Invalid States it show's you're trying to call isPlaying() while the player is in the error state. So you need to work out why it is already in the error state.
Have a look at adding an error listener: setOnErrorListener()
使用以下代码,因为我遇到了相同的异常。
在这里写下你想做的任何事情。实际上,像
isPlaying()
这样的条件检查或检查 null 会生成 IllegalStateException......Use the following code as i was facing the same exception.
Here write whatever you want to do. Actually the condition checking like
isPlaying()
or checking for null generates the IllegalStateException.....您可能需要清除与audioStream连接的audioGroup。我的工作使用以下代码:
You may have to clear the audioGroup joined with audioStream. Mine worked with the following code: