MediaPlayer error: pause called in state 64

前端 未结 5 1155
醉话见心
醉话见心 2020-12-30 05:30

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(18         


        
5条回答
  •  星月不相逢
    2020-12-30 06:05

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

提交回复
热议问题