同时播放多个声音 [英] Play multiple sound at the same time

查看:139
本文介绍了同时播放多个声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < audio controls =controls> 

我想使用HTML 5多重声音播放它怎么做?
< source src =audio /(TESBIHAT).mp3type =audio / mpeg/>
< source src =audio / Dombra.mp3type =audio / mpeg/>

< embed height =50pxwidth =100pxsrc =audio /(TESBIHAT).mp3/>
< embed height =50pxwidth =100pxsrc =audio / Dombra.mp3/>
< / audio>


解决方案

使用JavaScript和HTML5 Audio API,像这样:

  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(); //现在两者都会同时播放

我已经在Chrome v。20中对此进行了测试,它似乎工作:)



< source> 标记用于指定同一文件的不同格式 - 这样浏览器可以选择另一种格式作为后备,以防第一种格式不受支持。这就是为什么你自己建议的解决方案无效。


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

<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>

解决方案

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.

这篇关于同时播放多个声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆