Android media player returns IllegalStateException

后端 未结 3 1733
北荒
北荒 2021-01-12 00:25

I have following code to play small audio files

private void playVoice() {

     if (mPlayVoice != null) {
         if (mPlayVoice.isPlaying()) {
                    


        
3条回答
  •  温柔的废话
    2021-01-12 01:12

    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.....

提交回复
热议问题