gpt4 book ai didi

android - 媒体 Controller 隐藏但媒体播放器继续播放

转载 作者:行者123 更新时间:2023-11-29 21:10:45 27 4
gpt4 key购买 nike

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

我遇到了两个问题:

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

  2. 当我按下返回键时,之前的 Activity 启动,媒体 Controller 隐藏但媒体播放器继续播放

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

代码:

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

最佳答案

在你的 hide() 方法中试试这个:

super.hide();

代替:

mediaController.hide();

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

关于android - 媒体 Controller 隐藏但媒体播放器继续播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22947618/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com