我在这里厌倦了负荷和游戏方法:
http://chromium.googlecode.com/svn/trunk/samples/audio/doc/loading-sounds.html
并编写我自己的html和js代码,但加载音频时出现问题,我总是得到一个null bufferList和arraybuffer。我不知道为什么,有人请写一个简单的代码或告诉我如何在一个数组中加载音频,以便我可以使用websocket发送它
我不知道如何在这里添加代码,但我的代码与链接中的代码非常相似。
答案 0 :(得分: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();
}