Class: Music

Generic music player for a single music instance. Handles asynchronous loading of audio as well as “global” muting and window visibility events automatically.

Constructors

constructor

new Music(config): Music

Create a new music instance.

Parameters

Name Type Description
config MusicConfig Music configuration

Returns

Music

Properties

instance

Private instance: null | IMediaInstance


loadOptions

Private Optional loadOptions: LoadOptions


loadPromise

Private Optional loadPromise: Promise<void>


path

Private path: string


playing

Private playing: boolean


silencedUntil

Private silencedUntil: number


sound

Private sound: null | Sound


suspended

Private suspended: boolean


updateHandle

Private Optional updateHandle: number


volume

Private volume: number

Accessors

mute

get mute(): boolean

Global mute toggle for all music instances.

Returns

boolean

set mute(mute): void

Parameters

Name Type
mute boolean

Returns

void

Methods

load

load(): Promise<void>

Load the music asynchronously. Even though not necessary, calling load manually can be used to preload the music before playing.

Returns

Promise<void>


play

play(): void

Play the music.

If the music has not yet been loaded it will be automatically loaded asynchronously before the music will start playing - if the music has not been stopped before that.

Returns

void


silence

silence(duration): void

Silence the music for a given time.

Parameters

Name Type Description
duration number Silence duration in milliseconds

Returns

void


stop

stop(): void

Stop the music.

Returns

void


update

update(): void

Returns

void