Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play multiple sound at the same time

Tags:

Using HTML 5, I want to play multiple sounds simultaneously. how can I do it?

Here's what I currently have:

<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> 
like image 360
Polymorphism Avatar asked Jul 25 '12 14:07

Polymorphism


People also ask

How can I play multiple audios at the same time?

i) First, you can select a single app from the list to allow you to play sound in the background while another app is already playing audio. ii) Another option is, you can select “All apps” to turn on multi-stream audio. 4] Select your apps and you're good to go.

Can audio source play multiple sounds at once?

Whether sounds are played in 3D or 2D is determined by AudioImporter settings. You can play a single audio clip using Play, Pause and Stop. You can also adjust its volume while playing using the volume property, or seek using time. Multiple sounds can be played on one AudioSource using PlayOneShot.

How many sounds can Unity play at once?

For example, if the real voice limit is 32 (the default) and if there are 32 playing Audio Sources in the scene, but only one is actually audible, Unity will play all 32 sounds regardless.


1 Answers

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.

like image 120
Lasse Christiansen Avatar answered Oct 14 '22 03:10

Lasse Christiansen