I'm facing a frustrating issue in the Background Mode plugin in ionic. I'm developing a white noise application in Ionic 6 where the user can play multiple sounds at the same time. When a sound is activated, it is sent to the background, so I just leave the application and I can hear the sound playing normally even if I open other applications, so far so good.
The problem is when the app comes back to the foreground. If I click to stop the sound and click again to play, when I go back to the background, the sound starts playing about 2 seconds before, after those 2 seconds it starts playing normally. If I go back to the foreground and stop the sound and play it again, as soon as it returns to the background the sound increments, playing 2 seconds 2 times and only then starts normally.
It looks like it's slurring sounds in the background task list. Even if I pause all the sounds in the foreground, when I go back to the background it plays 2 seconds and stops the sound, as if they are in a queue. It appears to be a bug.
Based on this issue, my question is: How to reset or clear all background activity when my app is in foreground. That way I believe that every time my application goes to the background, the sounds are started from scratch, with no other in the queue.
clickSom1(){
if(this.som1 === false){
this.som1 = true;
this.nativeAudio.play('som1');
this.backgroundMode.on("activate").subscribe(()=>{
this.nativeAudio.play('som1');
});
}
else if(this.som1 === true){
this.som1 = false;
this.nativeAudio.stop('som1');
this.backgroundMode.on("activate").subscribe(()=>{
this.nativeAudio.stop('som1');
});
}