Come use our code #2: Browser Audio

It turns out that there are many things to think about when you're trying to play music or sound in a web browser. For example, there's an important difference between large files that can be played with high latencies (music tracks), which are best to stream, and low-latency short sound effects, which ought to be downloaded completely before the game starts. Another interesting point is the fact that fading is broken in Firefox. If you want to ramp volume, you've got to implement that yourself.

Here is a work-in-progress sound library that handles these considerations, and more. Hopefully some of you can benefit from it! Even if you don't want to include it, it might be a helpful example.

I am thinking that the fading implementation could use a rework, but IMO the loader and gain node stuff is relatively solid. Hopefully you will see some improvements as we get closer to the jam date. :)

https://github.com/Atomotron/ld47-prep/blob/master/sounds.js