Playing audio when app going to background

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.

Hi, have you found a solution?

I need this functionality, too. Anyone?

I solved this problem. follow link please…

Fixed!
It’s old but this maybe help someone.

We need to use backgroundMode plugin and use the event activate to play it again once go to background, so the music will be resume after we go to background, you will notice a tiny micropause.
Ionic v4 android 10

this.backgroundMode.enable();
this.backgroundMode.on("activate").subscribe(()=>{
   this.nativeAudio.play("audio1");  
});
this.nativeAudio.play("audio1"),() => console.log('audio1 is done playing'));