This page is work-in-progress. You can reach me on twitter or mail to rezoner1337@gmail.com

Setup

Instantiate an audio engine:

this.audio = new SoundOnDemand();

Channels

To play a sound through the audio engine you need a channel - and you can define as many channels as you want.

Imagine channel as a tube you are shouting through. Tube can has its own properies affecting volume and effects.

this.sound = this.audio.channel("sound");
this.music = this.audio.channel("music");

Play sound

Play sound through a channel.

this.sound.play("explosion");

This will look for sounds/explosion.ogg or sounds/explosion.mp3 depending on your prefered audio format and format supported by the browser and play it as soon as possible.

That's it. For more advanced features dig the documentation.

Preloading a sound

You don't have to preload audio. It gets loaded automatically on the first use and played as soon as possible. Nevertheless if you cannot any delay you can preload the sound:

this.audio.load("laser").then(success, error);

Loader returns a Promise that is fulfilled as soon as the sound has been loaded.

Ask question:

Fork me on GitHub