我创建了一个音乐播放器,该音乐播放器通过服务播放音乐,但是一段时间之后,当我不在应用程序外部时,音乐会随机停止,并且我得到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.
更多推荐
音频焦点客户端死于媒体播放器在后台播放音乐
发布评论