I have a collection of audio files with custom play/pause buttons that I've implemented.
Each audio file is assigned a dynamic class, such as custom-aud-0
, custom-aud-1
, custom-aud-2
, and so on...
Here is my toggle function:
togglePlay(c, index) {
this.is_playing ? this.pauseMe(c, index) : this.playMe(c, index);
},
playMe(c, index) {
document.getElementsByClassName(c)[0].play();
this.is_played = index;
this.is_playing = true;
},
pauseMe(c, index) {
document.getElementsByClassName(c)[0].pause();
this.is_played = null;
this.is_playing = false;
},
The desired functionality is that when one audio plays, if another audio is initiated, the previous one should automatically pause.
However, what actually occurs is that when a new audio starts playing, the previous one continues to play in the background.