2015-06-07 76 views
0

请家伙即时股票我需要帮助与这些我不断收到错误,缓冲区列表undefined,loadDogSound undefined.if没有得到任何错误,它不玩。网络音频api将不会播放声音

预先感谢您。

<script> 
 
window.onload = init; 
 
var context; 
 
var bufferLoader; 
 

 
function init() { 
 
    // Fix up prefixing 
 
    window.AudioContext = window.AudioContext || window.webkitAudioContext; 
 
    context = new AudioContext(); 
 

 
    bufferLoader = new BufferLoader(
 
    context, 
 
    [ 
 
     'audio/b.mp3', 
 
     'audio/a.mp3', 
 
    ], 
 
    finishedLoading 
 
    ); 
 

 
    bufferLoader.load(); 
 
} 
 

 
function finishedLoading(bufferList) { 
 
\t context = new AudioContext(); 
 
    // Create two sources and play them both together. 
 
    var source1 = context.createBufferSource(); 
 
    var source2 = context.createBufferSource(); 
 
    source1.buffer = bufferList[0]; 
 
    source2.buffer = bufferList[1]; 
 

 
    source1.connect(context.destination); 
 
    source2.connect(context.destination); 
 
    source1.start(0); 
 
    source2.start(0); 
 
} 
 

 
</script>

+0

你使用什么浏览器?不久前,这是非常实验性的,你必须用铬合金来打开它。今天应该可以在几乎所有流行的浏览器中使用。检查这里:http://caniuse.com/#search=AudioContext – oscargilfc

回答

0

它看起来像你正试图使一个脚本,引用此页面上讨论的对象:http://middleearmedia.com/web-audio-api-bufferloader/

按照说明,您应该创建一个名为buffer- loader.js,并将以下行放在html文件的头部:

<script type="text/javascript" src="buffer-loader.js"></script> 

这里是您为了方便而丢失的文件的一个pastie:http://pastie.org/10227922

当我添加此文件时,您的示例可正常工作。

+0

其实我没有从你给的链接得到它,但谢谢。我把它从[链接](http://www.html5rocks.com/en/tutorials/webaudio/intro/) –