MediaPlayer error: pause called in state 64

痞子三分冷 提交于 2019-11-30 13:13:02

问题


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?


回答1:


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 onPause such that it does not try to pause the stopped MediaPlayer.

Perhaps:

    if(mp!= null) {
       if(mp.isPlaying()) mp.pause();
    }

Actually don't do this, I just found this in the docs:

Note that the transition from the Started state to the Paused state and vice versa happens asynchronously in the player engine. It may take some time before the state is updated in calls to isPlaying(),

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 call pause().




回答2:


I used pause and seekto method to reset the player.

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



回答3:


I have come here looking for answers, though the responses above were useful in other things, they did not solve my problem...

BUT ... I managed to fix the problem:

changing mediaPlayer.stop();

to

mediaPlayer.reset();

helped me get rid off the error( -38 , 0 )

thanks again for pointing out the problem :)




回答4:


After facing an issue in starting the media player after stopping it, i got an exception and mp was an able to start again, then when replacing mp.stop() with mp.reset() it worked perfectly.




回答5:


Even I've faced the similar problem with same error.

I used mplayer.pause() instead of mplayer.stop()



来源:https://stackoverflow.com/questions/12520036/mediaplayer-error-pause-called-in-state-64

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!