Audio focus client died with media player playing

2019-07-11 21:04发布

问题:

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:

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.