2 audio sounds and I want to play one HTML5 audio element at a time

前端 未结 1 2079
遇见更好的自我
遇见更好的自我 2021-01-24 22:58

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

1条回答
  •  情话喂你
    2021-01-24 23:34

    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;
    

    fiddle demo

    or you can simply generalize it by:

    var audios = document.getElementsByTagName('audio');
    for(var i=0; i

    fiddle demo

    0 讨论(0)
提交回复
热议问题