goldfire / howler.js

Javascript audio library for the modern web.
https://howlerjs.com
MIT License
23.81k stars 2.23k forks source link

Playing multitrack files #1186

Open d-ark opened 5 years ago

d-ark commented 5 years ago

Hi!

I'm trying to use howler.js for playing multiple tracks (up to 12 audio files) synced. (See this StackOverflow question )

When I tried to do so - I noticed that files are downloaded to the memory and only start playing when fully received from server.

Do you have any buffering mechanism implemented in howler? Can I play like 2-3 hours files in it without downloading it all?

st-h commented 5 years ago

You can always enable hmtl5 mode, which gives you streaming behaviour - however your server needs to support range requests.

Yet, there is no synchronisation between your multitrack files. Even if you manage to start them all at the same time, they might get out of sync sooner or later.

Afaik, there currently is no easy way to do what you are looking for. From https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode

To play sounds which require accurate timing but must be streamed from the network or played from disk, use a AudioWorkletNode to implement its playback.

surprise, surprise, this is not widely supported yet and I have so far not come across any example on how to actually implement that.

One thing that might work is to implement fetching of chunks over the network and the decoding process yourself and use small chunks to schedule AudioBufferSourceNodes at the correct positions that only need to contain decoded data of small chunks. That at least would give you streaming and accurate playback. Sorry, I can't be of any more help right now. I have a similar issue on my todo list.