我在这里尝试了加载和播放方法:
http://chromium.googlecode.com/svn/trunk/samples/audio/doc/loading-sounds.html
并编写我自己的 html 和 js 代码,但在加载音频时遇到问题,我总是得到 null
bufferList
和 arraybuffer
。我不知道为什么,请有人写一个简单的代码或告诉我如何在数组中加载音频,以便我可以使用 websocket 发送它试试这个:
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();
}