Android media player returns IllegalStateException

て烟熏妆下的殇ゞ 提交于 2019-12-01 03:35:22
Blundell

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()

picaso

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());
            }
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!