Sound
engine.sound: Web Audio, loaded by name with engine.load, quiet while the host pauses, shows a break or is muted.
Example
Section titled “Example”await engine.load({ pop: 'sounds/pop.mp3' })engine.sound.play('pop', { volume: 0.8 })engine.sound.tone(880, 0.15)Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Sound():
Sound
The engine makes it (engine.sound); browsers unlock its audio on the first touch, key or click.
Returns
Section titled “Returns”Sound
Properties
Section titled “Properties”muted:
boolean
Muted by the host (the TV’s sound is off): set by the engine.
volume
Section titled “volume”volume:
number
Master volume, 0–1.
Methods
Section titled “Methods”context()
Section titled “context()”context():
AudioContext|null
The audio context, made on first use (null without Web Audio).
Returns
Section titled “Returns”AudioContext | null
load()
Section titled “load()”load(
name,url):Promise<void>
Decodes a sound file (mp3, aac, ogg, wav) under a name.
Parameters
Section titled “Parameters”string
string
Returns
Section titled “Returns”Promise<void>
has(
name):boolean
Whether a sound of that name is loaded.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
play()
Section titled “play()”play(
name,o?): () =>void
Plays a loaded sound; returns stop().
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”() => void
tone()
Section titled “tone()”tone(
freq,seconds?,o?):void
A short tone (a “ding”): frequency Hz, seconds, fading out.
Parameters
Section titled “Parameters”number
seconds?
Section titled “seconds?”number
Returns
Section titled “Returns”void
hold()
Section titled “hold()”hold():
void
Pauses and breaks: everything stops until release().
Returns
Section titled “Returns”void
release()
Section titled “release()”release():
void
Sound again after hold().
Returns
Section titled “Returns”void
destroy()
Section titled “destroy()”destroy():
void
Closes the audio context.
Returns
Section titled “Returns”void