Note that there are some explanatory texts on larger screens.

plurals
  1. POload & play multiple files at once from a array of location names
    text
    copied!<pre><code>window.onload = init; var list = new Array(); //array containing list of music sources var playListBuffer = new Array(); //array to put in all decoded audio var playList = new Array(); var context = new webkitAudioContext(); function init(){ list = ["../media/cello_suit.mp3","../media/morning.mp3"]; //list of files to play at once load(list); } function load(url){ for (var i=0; i&lt;list.length; i++){ //load in every url var request = new XMLHttpRequest(); request.open('GET', list[i], true); request.responseType = 'arraybuffer'; request.onload = function () { //Async method console.log(request.response); context.decodeAudioData(request.response, function(buffer) { //Async method if (!buffer) { alert('error decoding file data: '); return; } playListBuffer.push(buffer); //Decode audio and put inside playListBuffer if (list.length==playListBuffer.length){ console.log(playListBuffer); //When All files have been decoded show an Array in console prepare(); } }, function(e) { console.log('Error decoding audio file', e)}); }; request.onerror = function() { alert('BufferLoader: XHR error'); } request.send(); } } function prepare(){ for (var i=0; i&lt;playListBuffer.length; i++){ var source = context.createBufferSource(); // creates a sound source console.log(playListBuffer[i]); source.buffer = playListBuffer[i]; // tell the source which sound to play source.connect(context.destination); // connect the source to the context's destination (the speakers) playList.push(source); } playAll(); } function playAll(){ for (var i=0; i&lt;playList.length; i++){ playList[i].noteOn(0); } } </code></pre> <p>Hi; I have some strage behaviour on this basic script which uses the new webaudio api. This script throws in error in chrome: Uncaught Error: SYNTAX_ERR: DOM Exception 12 audio.js:27 request.onload; however if I remove the second element in my list it works. Why?</p> <p>Background info: this script read an array of song locations and plays them simultaneously.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload