The problem is that you are not monitoring the state of your MediaPlayer instance.
Before calling isPlaying() you only check for null , although player can still be released (but not null ).
Calling isPlaying() on the released MediaPlayer instance will IllegalStateException .
To avoid this, you can, for example, set player to null when it is released:
player.release(); player = null;
Or you can use the boolean flag to track its status:
boolean isReleased;
Thus, you can check this flag if necessary:
if (player != null && !isReleased) { if(player.isPlaying()) {
(don't forget to set it false if necessary)
source share