媒体控制器隐藏但媒体播放器继续播放

时间:2014-04-08 20:34:33

标签: android android-mediaplayer mediacontroller

我有一个媒体播放器并与媒体控制器相关联。控件工作正常。

我遇到两个问题:

  1. 当媒体控制器获得焦点时,即用户触摸它然后触摸屏幕的另一部分,媒体控制器会隐藏,但媒体播放器会继续播放,

  2. 当我按下时,之前的活动启动,媒体控制器隐藏但媒体播放器继续播放

  3. 我已经尝试了下面的代码,但它崩溃了应用程序,出现以下错误。有什么建议吗?

    代码:

    mediaController = new MediaController(getActivity()){
                                @Override
                                public void hide()
                                {
    
                                    if(mediaPlayer.isPlaying()){
                                        mediaPlayer.stop();
                                    }
                                    mediaController.hide();
                                }
    
    
                            };
    

    应用崩溃时的堆栈跟踪:

    04-09 00:32:49.841: E/AndroidRuntime(3911): FATAL EXCEPTION: main
    04-09 00:32:49.841: E/AndroidRuntime(3911): Process: com.itspirits.lifenavigatorlite, PID: 3911
    04-09 00:32:49.841: E/AndroidRuntime(3911): java.lang.StackOverflowError
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:214)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.ArticleFragment$2$2.hide(ArticleFragment.java:217)
    04-09 00:32:49.841: E/AndroidRuntime(3911):     at com.itspirits.lifenavigatorlite.Artic
    

1 个答案:

答案 0 :(得分:2)

在hide()方法中尝试:

super.hide();

而不是:

mediaController.hide();

看起来你已经创造了一个永恒的循环。