Ionic / Android 8+: Audio stops playing after about 5 mins when screen is locked

My app plays music using the cordova-plugin-media plugin. cordova-plugin-background-mode is handling the background tasks.

This block of code is present in my app.component.ts:

platform.ready().then(() => {
    this.backgroundMode.setDefaults({
        title: 'MyMusicApp',
            text: 'Android 8 problem!',
            resume: true,
            hidden: true,
            silent: true
    });
}

And when the media player provider component receives a ‘play’ command, it calls:

this.backgroundMode.enable();

On Android 6 and 7, the audio nicely plays in the background when the screen is locked. However, on Android 8, every single time, when the screen is locked (or times out), after about 5 minutes, the background audio is cut off.

From what I read, Android 8+ is using a new implementation to handle 3rd party apps that keep active or are using resources in the background. The solution above was an attempt at solving this cut-off problem, but it does not seem to help…

Would anyone be able to offer help with this? How can the background audio best be handled on Android 8?

Bumping up. Surely someone else must have noticed the same behavior with the media plugin? Anyone has a possible idea about how to handle this? This behavior is really bad, as users tend to think the app is causing the problem :frowning:

hi, Did you resolve this?
Do you specifically start a background process(in your case playing the audio file) when the ‘activate’ event is fired when app goes into background mode?

HI, I have the same problem