2015-10-04 60 views
0

它適用於單個文件:howler.js支持多種音頻文件

<button id="btn">Play</button> 
<script> 
var btn = new Howl({urls: ['http://www.javascriptoo.com/application/html/btn.wav']}) 
document.getElementById('btn').onclick=function(){btn.play()} 
</script> 

但我需要發揮多個文件:

<button id="btn2">Play</button> 
<button id="btn3">Play</button> 
<button id="btn23">Play</button> 

這是任何簡單的方法來解決呢?

回答

1

無論是結合不同的聲音到音頻精靈(推薦方法):

var btn1 = new Howl({ 
    urls: ['http://www.javascriptoo.com/application/html/btn1.wav'] 
}); 
document.getElementById('btn1').onclick = function(){ 
    btn1.play(); 
}; 

var btn2 = new Howl({ 
    urls: ['http://www.javascriptoo.com/application/html/btn2.wav'] 
}); 
document.getElementById('btn2').onclick = function(){ 
    btn2.play(); 
}; 

var btn3 = new Howl({ 
    urls: ['http://www.javascriptoo.com/application/html/btn3.wav'] 
}); 
document.getElementById('btn3').onclick = function(){ 
    btn3.play(); 
}; 

var btns = new Howl({ 
    urls: ['http://www.javascriptoo.com/application/html/btn.wav'], 
    sprite: { 
    btn1: [0, 1000], 
    btn2: [2000, 3000], 
    btn3: [4000, 5000] 
    } 
}); 

或者,你可以設定每個按鈕創建一個新Howl