MediaPlayer error: pause called in state 64

erdomester picture erdomester · Sep 20, 2012 · Viewed 14.5k times · Source

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?

Answer

Goran Horia Mihail picture Goran Horia Mihail · Apr 22, 2014

I used pause and seekto method to reset the player.

player.pause();
player.seekTo(0);