Audio - globules-io/OGX.JS GitHub Wiki

Audio is an object that makes the link between stored audio files in Cache and Howler.js. All sounds added to the preload tag of app.json will be stored in OGX.JS's cache and can be accessed or played using Audio. All sounds are played via Howler.

Formats

OGX.JS supports mp3 ogg webm and wav files.

Preload

OGX.JS provides a mechanism to preload and store sounds. Add references to the sounds to be preload in the app.json configuration such as

 {...,
      preload:{              
           "/snd":["click.mp3", "msg.mp3"]
           
      }, ...
 }

Play

To play a cached sound. Options is an optional object to configure Howler

 OGX.Audio.play(_ID_, _OPTIONS_);

A practical example

 OGX.Audio.play('click', {volume: 0.5, loop: false});

Get

To retrieve a preloaded sound

 OGX.Audio.get(_ID_);

Prepare

To convert all preloaded sounds into Howls. Options is an optional object to configure Howler. If sounds are not prepared, each sound will be converted to a Howl at runtime.

 OGX.Audio.prepare(_OPTIONS_);