Android的媒体播放器返回IllegalStateException异常 [英] Android media player returns IllegalStateException
问题描述
我有以下code打小的音频文件
私人无效playVoice(){
如果(mPlayVoice!= NULL){
如果(mPlayVoice.isPlaying()){
mPlayVoice.release();
mPlayVoice = NULL;
}
}
mPlayVoice =
MediaPlayer.create(BirdsActivity.this,mSoundIds [getCurrentIndex()]);
mPlayVoice.start();
}
它工作正常,在三星Galaxy Tab,但给下面的错误在小型设备(我检查了索尼Xperia mini pro的我的项目)
十二月8号至17日:45:45.232:ERROR / AndroidRuntime(6639):java.lang.IllegalStateException
12月8日至17号:45:45.232:ERROR / AndroidRuntime(6639):在android.media.MediaPlayer.isPlaying(本机方法)
12月8日至17号:45:45.232:ERROR / AndroidRuntime(6639):在com.android.mds.kidsapps.alphakids.BirdsActivity.playVoice(BirdsActivity.java:146)
您正在做这样的:
PlayVoice.release();
你不是说
mPlayVoice.release();
如果您还有其他问题,这是咨询最好的文档:
修改的
如果你在这里好了:<一href="http://developer.android.com/reference/android/media/MediaPlayer.html#Valid_and_Invalid_States"相对=nofollow> IsPlaying模块()无效的国家该节目的你试图调用IsPlaying模块(),而播放器处于错误状态。所以,你需要找出为什么它的已的错误状态。
在一般情况下,某些重放控制操作可能由于各种原因,诸如不支持的音频/视频格式,很差交错的声音/视频,分辨率过高,流超时等失败。
看一看增加错误监听器:<一href="http://developer.android.com/reference/android/media/MediaPlayer.html#setOnErrorListener%28android.media.MediaPlayer.OnErrorListener%29"相对=nofollow> setOnErrorListener()
I have following code to play small audio files
private void playVoice() {
if (mPlayVoice != null) {
if (mPlayVoice.isPlaying()) {
mPlayVoice.release();
mPlayVoice = null;
}
}
mPlayVoice =
MediaPlayer.create(BirdsActivity.this, mSoundIds[getCurrentIndex()]);
mPlayVoice.start();
}
It works fine in Samsung galaxy tab but gives below error in small device(I Checked in Sony xperia mini pro my project)
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)
You're doing this:
PlayVoice.release();
Do you not mean
mPlayVoice.release();
If you have other issues this is the best document to consult:
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.
In general, some playback control operation may fail due to various reasons, such as unsupported audio/video format, poorly interleaved audio/video, resolution too high, streaming timeout, and the like.
Have a look at adding an error listener: setOnErrorListener()
这篇关于Android的媒体播放器返回IllegalStateException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!