1681-engine / index / MusicPlayer
Class: MusicPlayer ​
Defined in: src/audio/MusicPlayer.ts:38
Background music in layers: each named channel ('music' by default, 'ambience', any other) plays one looping track at a time, crossfaded when it changes, all at engineSettings.musicVolume. Tracks stream through <audio> elements (no decoding a whole song into memory).
Browsers start sound only after a user gesture: a track played before one starts on the first tap or key. On iOS the graph's context is woken inside that gesture too, and again after the app comes back from the background.
music.play('music/forest.ogg'); // the 'music' channel
music.channel('ambience').play('amb/wind.ogg', { volume: 0.5 }); // a second layer under it
music.play('music/boss.ogg', { fadeMs: 600 }); // crossfades the first only
music.stop(2000);Constructors ​
Constructor ​
new MusicPlayer(): MusicPlayer;Returns ​
MusicPlayer
Accessors ​
current ​
Get Signature ​
get current(): string | null;Defined in: src/audio/MusicPlayer.ts:65
The url the 'music' channel plays, if any.
Returns ​
string | null
Methods ​
channel() ​
channel(name?): MusicChannel;Defined in: src/audio/MusicPlayer.ts:54
The channel named name, made on first use.
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
name | string | 'music' |
Returns ​
configure() ​
configure(options): this;Defined in: src/audio/MusicPlayer.ts:47
Picks the route and background behaviour; call before the first track for the route to apply to every track.
Parameters ​
| Parameter | Type |
|---|---|
options | MusicOptions |
Returns ​
this
destroy() ​
destroy(): void;Defined in: src/audio/MusicPlayer.ts:87
Returns ​
void
pause() ​
pause(): void;Defined in: src/audio/MusicPlayer.ts:79
Returns ​
void
play() ​
play(url, options?): void;Defined in: src/audio/MusicPlayer.ts:70
Plays url on the 'music' channel.
Parameters ​
| Parameter | Type |
|---|---|
url | string |
options? | MusicPlayOptions |
Returns ​
void
resume() ​
resume(): void;Defined in: src/audio/MusicPlayer.ts:83
Returns ​
void
stop() ​
stop(fadeMs?): void;Defined in: src/audio/MusicPlayer.ts:75
Fades every channel out.
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
fadeMs | number | 1200 |
Returns ​
void