2012-06-19 100 views
2

播放一段音頻我厭倦了load和play方法在這裏:
http://chromium.googlecode.com/svn/trunk/samples/audio/doc/loading-sounds.html
,寫我自己的HTML和JS代碼,但得到加載音頻問題,我總是得到一個空bufferList和arraybuffer。我不知道爲什麼,有人請寫一個簡單的代碼或告訴我如何加載數組中的音頻,以便我可以使用websocket發送它
我不知道如何在這裏添加代碼,但我的代碼是與鏈接代碼非常相似。有負載的問題,並使用JS

回答

0

試試這個:

window.onload = init(); 

function init() 
{ 
var audioContext = new webkitAudioContext(); 

var source = audioContext.createBufferSource(); 
source.connect(audioContext.destination); 

var xhr = new XMLHttpRequest(); 
xhr.open("GET", "sounds/sample.mp3", true); 
xhr.responseType = "arraybuffer"; 
xhr.onload = function() { 
    var buffer = audioContext.createBuffer(xhr.response, false); 
    source.buffer = buffer; 
    source.noteOn(0); 
}; 
xhr.send(); 
}