MediaPlayer的错误:暂停调用状态64 [英] MediaPlayer error: pause called in state 64

查看:258
本文介绍了MediaPlayer的错误:暂停调用状态64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于MediaPlayer的错误:暂停调用状态64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆