音频焦点客户端死于媒体播放器在后台播放音乐

编程入门 行业动态 更新时间:2024-10-25 00:28:20
本文介绍了音频焦点客户端死于媒体播放器在后台播放音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建了一个音乐播放器,该音乐播放器通过服务播放音乐,但是一段时间之后,当我不在应用程序外部时,音乐会随机停止,并且我得到Log Massage音频焦点客户端死了",我无法弄清楚这个..为什么会这样

I have created a music player which plays music through service, but after some time when i am outside the app music stops at random time, and i am getting the Log massage "Audio focus client died",i am not able to figure this out..why this is happening

我没有附加任何代码源,因为这实际上是一个简单的代码,不会执行任何复杂的任务,只是播放音乐的一项服务和监视音频焦点的一个Audio Focus Helper.

I am not attaching any code source because this is really a simple code that is not doing any complex task Just one service that playing music and one Audio focus helper which monitor the focus of audio..

推荐答案

这可能是因为Android OS因缺乏资源而终止了该服务.您可以将其服务前景作为避免这种情况的方法.这是代码段:

It may be because the Android OS would have killed the service due to lack of resources. You can make your service foreground to avoid it. Here is the snippit:

private void sendToForeground() { Notification note = new Notification(0, null, System.currentTimeMillis()); note.flags |= Notification.FLAG_NO_CLEAR; startForeground(0, note); }

只需在服务的onCreate中调用它即可.

Just call it in onCreate of service.

更多推荐

音频焦点客户端死于媒体播放器在后台播放音乐

本文发布于:2023-07-11 09:09:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1093530.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:媒体播放器   死于   客户端   后台   音频

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!