Reputation: 2607
Does anyone have any examples or suggestions on how to go about streaming large audio files for the Web Audio API? Reading the W3C spec, they recommend streaming when the files are large versus an XMLHTTPRequest (note: there is currently a bug preventing the opening of large files Chromium Issue 71704)
The examples provided by Google all show use of XMLHTTPRequest to load small (<1MB Wave files)
Any help would be appreciated.
Thanks
Upvotes: 8
Views: 5629
Reputation: 7481
The <audio>
element is the way to go, as it handles streaming and buffering under the hood. As of Chrome 18, you can use <audio>
elements as input sources for further processing with createMediaElementSource()
. Check out more information here:
http://updates.html5rocks.com/2012/02/HTML5-audio-and-the-Web-Audio-API-are-BFFs
Upvotes: 8
Reputation: 24109
This doesn't directly answer your question but it will be helpful.
An asynchronous decodeAudioData
method was added to the API. That will still use XHR, but it's worth switching your code over to it. The new method is available in Chrome 14.
// Use async decoder if it is available.
if (context.decodeAudioData) {
context.decodeAudioData(arrayBuffer, function(buffer) {
source.buffer = buffer;
}, function(e) {
console.log(e);
});
} else {
source.buffer = context.createBuffer(arrayBuffer, false);
}
Upvotes: 7