I have following code to play small audio files
private void playVoice() {
if (mPlayVoice != null) {
if (mPlayVoice.isPlaying()) {
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());
}
}