Reputation: 84550
I'm trying to set up some WebAudio code. I've created a context, and now I'm trying to load some sounds. (WAV files.) I set up an XHR object and attach the following event:
request.onload = function (response) {
context.decodeAudioData(request.response,function (buffer) {
this.Buffer = buffer;
});
I've verified that the XHR fires correctly, and the onload
callback gets called every time, and that the response is a valid arraybuffer, and that the WAV files being requested are good. But for some reason, when I run this routine multiple times, the callback I pass into decodeAudioData
only fires once or twice, and the rest of the time it never returns. Then when I go to play the sound later, I get an exception because it's not set up.
Using Chrome version 33.0.1750.154 m. Does anyone have any idea what can cause decodeAudioData to not call its callback?
Upvotes: 1
Views: 670
Reputation: 1951
If you're saying that you can't call decodeAudioData more than once on the same ArrayBuffer, it's because it's a destructive function. After you pass an ArrayBuffer to it, it will destroy that buffer. IIRC it's done to save memory.
If you're saying that you can't call decodeAudioData more than once with different files / ArrayBuffers, that is something entirely different.
(Yes, I realize the original question was from 2014. Just leaving this answer for the benefit of anyone else from the distant future who stumbles across it.)
Upvotes: 0
Reputation: 11
I've run into this issue too. It seems the code behind web audio api is a bit buggy because if I use alert boxes to check state during the processing of decodeaudiodata (windows 8 64bit environment), it will not properly call the success or error callbacks. My code was working fine and then my iPad mini got an update of chrome, but after the latest update to the version you have, my ipad never has the success or error get called back properly yet the windows 8 chrome works fine with the same page (as long as there are no alert boxes during the processing).
Windows 8 w/chrome 33.0.1750.154 - will call success callback as long as there are no alert windows shown during processing.
iPad mini w/chrome 33.0.170.154 (as well as Safari) - will never call success or error callback regardless of alert windows. This was working in prior versions of chrome.
edit - its not just alerts, using breakpoints in debugger causes the same issue.
Looking for a demo page: http://kusogmusic.com/violin/drones and http://kusogmusic.com/violin/playalong
Upvotes: 0
Reputation: 13908
Invalid WAV file or other problem decoding, most likely. Can you set the onerror callback, or share a file that doesn't work?
Upvotes: 1