this.list = [
"LaserShot", //http://www.freesound.org/samplesViewSingle.php?id=39459
"Ding", //http://www.freesound.org/samplesViewSingle.php?id=5212
"Rocket" //http://www.freesound.org/samplesViewSingle.php?id=47252 -> http://creativecommons.org/licenses/sampling+/1.0/
];
...
for (i in this.list) {
this.sounds[this.list[i]] = new Array();
for (var j = 0; j < this.channels; j++) {
this.sounds[this.list[i]][j] = new Audio("./sounds/"+ this.list[i] + type);
}
}
我只是想这样做:
for (i in this.list) {
this.sounds[this.list[i]] = new Array();
var tempAudio = new Audio("./sounds/"+ this.list[i] + type);
for (var j = 0; j < this.channels; j++) {
this.sounds[this.list[i]][j] = realCopyOfTempAudio;
}
}
非常感谢你。
答案 0 :(得分:0)
我的经历:
最好使用相同的源创建更多音频html标签。我是js的粉丝,但这次最好以html格式提供html音频标签。
我制作了重复的音频标签,我装饰了我的需求。如果你想在一秒钟内多次播放相同的声音,那么添加更多克隆。
你也可以修复自动播放错误 (而不是EXE_JUST_ONE_TIME你可以使用覆盖点击事件,现在不重要):
<audio controls id="LaserShot" >
<source src="LaserShot.mp3" type="audio/mpeg">
<source src="LaserShot.ogg" type="audio/ogg">
</audio>
<audio controls id="LaserShot_CLONE" >
<source src="LaserShot.mp3" type="audio/mpeg">
<source src="LaserShot.ogg" type="audio/ogg">
</audio>
<script>
var EXE_JUST_ONE_TIME = false;
document.addEventListener("click" , function(e) {
if (EXE_JUST_ONE_TIME == false){
EXE_JUST_ONE_TIME = true;
document.getElementById("LaserShot").play();
document.getElementById("LaserShot").pause();
document.getElementById("LaserShot_CLONE").play();
document.getElementById("LaserShot_CLONE").pause();
// Buffering in progress
// now you can play programmability from code
// One click or touch can prepare max 6 audios
}
}
Last part (need to be handled) this handler works only for one clone:
var play_shoot = function(){
if (document.getElementById('LaserShot').duration > 0 &&
!document.getElementById('LaserShot').paused) {
document.getElementById('LaserShot_CLONE').play();
} else {
document.getElementById('LaserShot').play();
}
}