MediaPlayer的错误:暂停调用状态64状态、错误、MediaPlayer

由网友(义字当头.)分享简介:我使用的是媒体播放器在我的活动。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...

我使用的是媒体播放器在我的活动。

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)



  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);
        }

如果我用mp.pause(),它的正常工作。为什么呢?

If I use mp.pause(), it's working fine. Why?

推荐答案

这是非法的暂停停止的MediaPlayer,并根据这听起来完全像你在做什么错误信息。

It's illegal to pause a stopped MediaPlayer, and according to that error message that sounds exactly like what you're doing.

我建议改变你的onPause使得它不会尝试暂停停止MediaPlayer的。

I suggest changing your onPause such that it does not try to pause the stopped MediaPlayer.

也许是:     如果(熔点!= NULL){        如果(mp.isPlaying())mp.pause();     }

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

其实不这样做,我只是发现了这个在文档:

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

请注意,从开始状态为暂停状态,反之亦然过渡异步发生在播放器引擎。这可能需要一些时间之前的状态在调用更新为IsPlaying模块()

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.

阅读全文

相关推荐

最新文章