Reputation: 16780
I am using a MediaPlayer to play music in my app. When I need to pause and resume, I check for the status using mPlayer.isPlaying() but this throws an illegal state exception at times.
Why does this happen? And what should you do in these times? How would you determine the state of the player?
Upvotes: 1
Views: 4276
Reputation: 692
According to the Android docs:
"IllegalStateException if the internal player engine has not been initialized or has been released."
I would say first make sure that you have initialized and/or have not released the player.
MediaPlayer can be strange though; it's worth playing around with different statements even if the logic already makes sense; I could help you more in this regard if you posted code.
For now, you could just use a try-catch statement and put something in the catch to ensure that MediaPlayer is working properly.
Edit1: Just a guess in the dark, if you are using a static global variable for your MediaPLayer, that could be the problem. I would double check how it's being initialized and released, especially when switching between classes and such.
Upvotes: 5