I am using a MediaPlayer in my Activity.
When I hit the back button, I get this error:
09-20 19:44:16.540: E/MediaPlayer(1822): pause called in state 64
09-20 19:44:16.540: E/MediaPlayer(1822): error (-38, 0)
Code
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
if (mp!= null && mp.isPlaying()) {
mp.stop();
}
Intent intentstart = new Intent(X.this, Y.class);
intentstart.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intentstart);
}
return super.onKeyDown(keyCode, event);
}
If I use mp.pause(), it’s working fine. Why?
It’s illegal to pause a stopped
MediaPlayer, and according to that error message that sounds exactly like what you’re doing.I suggest changing your
onPausesuch that it does not try to pause the stoppedMediaPlayer.Perhaps:
if(mp!= null) { if(mp.isPlaying()) mp.pause(); }Actually don’t do this, I just found this in the docs:
You should maintain a variable locally to check if you’ve already stopped the
MediaPlayer, and then test that for whether or not you should callpause().