I am encountering an issue in Angular where I am unable to stop playing an audio from a service. Below is my play()
method:
play(item: string): void {
const audio = new Audio();
audio.src = item;
audio.load();
audio.play();
}
In order to stop all currently playing audios, I created a mute()
method within my component:
mute(): void {
const sounds = document.getElementsByTagName('audio');
console.log(sounds);
for (let i = 0; i < sounds.length; i++) {
sounds[i].pause();
}
}
Unfortunately, the console.log
does not display any sounds and as a result, none of them are being paused as intended.