简体   繁体   中英

web audio api wont play sound

pls guys im stock i need help with these i keep getting errors,bufferlist undefined,loadDogSound undefined.if dont get any error it doesnt play.

Thank you in advance.

 <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) { 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> 

It looks like you are trying to make a script that references an object discussed on this page: http://middleearmedia.com/web-audio-api-bufferloader/

According to the instructions you should have created a file called buffer-loader.js and put the following line in the head of your html file:

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

Here is a pastie to the file you are missing for your convenience: http://pastie.org/10227922

When I add this file, your example works without error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM