Audio focus client died with media player playing

2019-07-11 21:21发布

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

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..

1条回答
手持菜刀,她持情操
2楼-- · 2019-07-11 21:49

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);
}

Just call it in onCreate of service.

查看更多
登录 后发表回答