var shots = Math.ceil(Math.random(0,1)*5);
var snd = new Audio("test.wav");
for (var i = 0; i < shots; i++){
snd.play();
}
现在,根据要发射多少“镜头”,我想播放test.wav相同的次数,并且它们之间具有随机的,非常短的延迟,甚至彼此之间甚至有“重叠”的音效。
我将如何最好地做到这一点?
- 谢谢
最佳答案
我会喜欢...
var shots = Math.ceil(Math.random()*5), // Math.random() --> always 0-1 range
src = 'http://upload.wikimedia.org/wikipedia/en/f/f9/Beatles_eleanor_rigby.ogg', // change to your source
maxStartTime = 1000;
for(var i=0;i<shots;i++){
setTimeout(function(){
(new Audio(src)).play();
}, 100 + maxStartTime*(Math.random())); // again you can calibrate the timeout value to what suits you best
}
关于javascript - audio.play()和多个效果播放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29185078/