Play multiple sound at the same time

前端 未结 1 680
盖世英雄少女心
盖世英雄少女心 2020-12-08 11:34

I want using HTML 5 multiple sound play how do it ?

相关标签:
1条回答
  • 2020-12-08 12:07

    With JavaScript and the HTML5 Audio API you could do something like this:

    var snd1  = new Audio();
    var src1  = document.createElement("source");
    src1.type = "audio/mpeg";
    src1.src  = "audio/Dombra.mp3";
    snd1.appendChild(src1);
    
    var snd2  = new Audio();
    var src2  = document.createElement("source");
    src2.type = "audio/mpeg";
    src2.src  = "audio/(TESBIHAT).mp3";
    snd2.appendChild(src2);
    
    snd1.play(); snd2.play(); // Now both will play at the same time
    

    I have tested this in Chrome v. 20, and it seems to work :)

    The <source> tag is used to specify different formats of the same file - such that the browser can choose another format as fallback in case the first one is not supported. That is why your own suggested solution does not work.

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