音频焦点客户端死于媒体播放器在后台播放音乐 [英] Audio focus client died with media player playing music in background

查看:198
本文介绍了音频焦点客户端死于媒体播放器在后台播放音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个音乐播放器,该音乐播放器通过服务播放音乐,但是一段时间之后,当我不在应用程序外部时,音乐会随机停止,并且我得到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.

这篇关于音频焦点客户端死于媒体播放器在后台播放音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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