开发者

Streaming Large Audio Files for Web Audio API

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: the开发者_运维百科re 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


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


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜