Skip to main content
Two client libraries play audio: Both have the same three methods: load(key, url), play(key) and mute().

Load your files

Put the audio files in your project’s assets folder, then load each one under a key after app.init:

Play

From a system, or anywhere you have the context:
  • ctx.music.play(key) stops the track that was playing before.
  • play throws NfNotFound when no file was loaded under that key.
  • Playing a sound that is already playing has no effect until it ends.

Turn the sound on

Both libraries start muted, and mute() toggles the muted state: call it once to turn the sound on. Browsers also block audio until the player has interacted with the page, so tie it to a key press or a click.
A system runs on every tick, so toggle on the press, not while the key is held: