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:
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.
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()
Use the following code as i was facing the same exception.
try {
if(mPlayVoice!=null && mPlayVoice.isPlaying()) {
Log.d("TAG------->", "player is running");
mPlayVoice.stop();
Log.d("Tag------->", "player is stopped");
mPlayVoice.release();
Log.d("TAG------->", "player is released");
}
} catch(Exception e){
}
Here write whatever you want to do. Actually the condition checking like isPlaying()
or checking for null generates the IllegalStateException.....
You may have to clear the audioGroup joined with audioStream. Mine worked with the following code:
public static void audioPlayCaptureStop()
{
try
{
if(audioStream.isBusy())
{
audioGroup.clear();
audioStream.release();
System.out.println("audioStream released");
}
} catch (Exception e) {
System.out.println("audioStream release exception: "+e.toString());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With