Web Audio API: How to play a stream of MP3 chunks
I see at least 2 possible approaches.
Setting up a
scriptProcessorNode
, which will feed queue of received & decoded data to realtime flow of web-audio.Exploiting the property of
audioBufferSource.loop
- updating audioBuffer’s content depending on the audio time.
Both approaches are implemented in https://github.com/audio-lab/web-audio-stream. You can technically use that to feed received data to web-audio.
Currently, decodeAudioData()
requires complete files and cannot provide chunk-based decoding on incomplete files. The next version of the Web Audio API should provide this feature: https://github.com/WebAudio/web-audio-api/issues/337
Meanwhile, I've began writing examples for decoding audio in chunks until the new API version is available.
https://github.com/AnthumChris/fetch-stream-audio
No, you can't reuse an AudioBufferSourceNode, and you cant push
onto an AudioBuffer. Their lengths are immutable.
This article (http://www.html5rocks.com/en/tutorials/audio/scheduling/) has some good information about scheduling with the Web Audio API. But you're on the right track.