2

I tired the load and play method here:
http://chromium.googlecode.com/svn/trunk/samples/audio/doc/loading-sounds.html
and write my own html and js code, but got problems loading the audio, I always get a null bufferList and arraybuffer. I don't know why, someone please write a simple code or tell me how can I load a audio in a array so that I can send it using websocket
I don't know how to add code here, but my code is very similar with the code from the link.

4

1 回答 1

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();
}
于 2013-04-17T12:54:43.583 回答