Question: I have 2 audio sounds and I want to play one HTML5 audio element at a time.
Similar Post: Play one HTML audio element at a time.
I saw a similar pos
I think the problem is you are listing to click
event, when you should be listening to play
event, also for some reason, window.onload
does not work properly in jsfiddle, so replace
window.onload = function () {
$("sound1").onclick = sound1_click;
$("sound2").onclick = sound2_click;
}
with
$("sound1").onplay = sound1_click;
$("sound2").onplay = sound2_click;
or you can simply generalize it by:
var audios = document.getElementsByTagName('audio');
for(var i=0; i