Play multiple sounds at the same time
P粉832212776
P粉832212776 2023-08-13 16:14:48
0
1
518
<p>Using HTML 5, I want to play multiple sounds at the same time. How do I do this? </p> <p>Here is my current code: </p> <pre class="brush:html;toolbar:false;"><audio controls="controls"> <source src="audio/(TESBIHAT).mp3" type="audio/mpeg" /> <source src="audio/Dombra.mp3" type="audio/mpeg" /> <embed height="50px" width="100px" src="audio/(TESBIHAT).mp3" /> <embed height="50px" width="100px" src="audio/Dombra.mp3" /> </audio> </pre>
P粉832212776
P粉832212776

reply all(1)
P粉682987577

Using JavaScript and the HTML5 Audio API, you can 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(); // 现在两者将同时播放

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

The

<source> tag is used to specify different formats of the same file - this way the browser can choose another format as a fallback if the first format is not supported. That's why your own proposed solution doesn't work.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!