My app is playing some audios depending on various triggers. I want the user to be able to stop the sound when he decides it.
this is what I did, based on this post:
audioPlayer(sound){
const audioGetReady = new Audio("...mp3")
const audioTenSec = new Audio("...mp3");
const audioNext = new AudioAudio("...mp3");
const audioRest = new AudioAudio("...mp3")
const audioCongrats = new AudioAudio("...mp3")
if(sound == 'getReady'){
audioGetReady.play()
}
if(sound == 'tenSeconds'){
audioTenSec.play()
}
if(sound == 'next'){
audioNext.play()
}
if(sound == 'rest'){
audioRest.play()
}
if(sound == 'congrats'){
audioCongrats.play()
}
if(sound == 'stop'){
audioGetReady.pause();
audioGetReady.currentTime = 0;
audioTenSec.pause();
audioTenSec.currentTime = 0;
audioNext.pause();
audioNext.currentTime = 0;
audioRest.pause();
audioRest.currentTime = 0;
audioCongrats.pause();
audioCongrats.currentTime = 0;
}
}
It doesn't work, I also tried to use ".muted = true;" as shown here