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?