Hi guys
My app plays audio here and there (I am using https://ionicframework.com/docs/native/native-audio/).
Since my app also contains a “timer” element I faced a “background” issue - when the screen was going off the app was paused and the timer didn’t advance. I managed to overcome this issue also by using this plugin (https://ionicframework.com/docs/native/background-mode/).
What I did was simply call the enable
method of the plugin when the timer starts its work:
def startTimer() {
this.backgroundMode.enable();
// start the timer
}
It worked as expected except one side effect.
If the screen goes off (or if I force it by pressing the phone’s lock button) while an audio is being played the audio stops. When I open the phone again the audio is played again from start.
I managed to make the audio continue after screen goes off by
this.backgroundMode.on('activate').subscribe(() => {
this.nativeAudio.play( /* current audio */ );
}
}
So this one makes the audio keep playing BUT when I resume the app once again, the audio is also played from start.
Does anyone has any idea how to block this behaviour?
Thanks.