Skip to content

Class: SoundManager

Constructors

Constructor

ts
new SoundManager(options: SoundManagerOptions): SoundManager;

Parameters

ParameterType
optionsSoundManagerOptions

Returns

SoundManager

Accessors

muted

Get Signature

ts
get muted(): boolean;

Indicates whether the SoundManager is currently muted.

Returns

boolean


ready

Get Signature

ts
get ready(): Promise<void>;

A promise that resolves when the SoundManager is fully initialized.

Returns

Promise<void>


unmuted

Get Signature

ts
get unmuted(): boolean;

Indicates whether the SoundManager is currently unmuted.

Returns

boolean


volume

Get Signature

ts
get volume(): number;

The current volume level of the SoundManager, represented as a number between 0 and 1.

Returns

number

Methods

cleanup()

ts
cleanup(): void;

Cleans up the SoundManager by stopping all audio elements and removing internal event listeners.

Returns

void


initialize()

ts
initialize(): Promise<void>;

Initializes the SoundManager by loading all audio elements and adding event listeners.

Returns

Promise<void>


mute()

ts
mute(): SoundManager;

Mutes all sounds played by the SoundManager.

Returns

SoundManager

The current instance of the SoundManager for easy chaining


off()

ts
off<K>(event: Key<K, SoundManagerEvents>, listener?: Listener<K, SoundManagerEvents>): this;

Removes an event listener from the SoundManager.

Type Parameters

Type Parameter
K

Parameters

ParameterTypeDescription
eventKey<K, SoundManagerEvents>The name of the event to unsubscribe from
listener?Listener<K, SoundManagerEvents>The callback to unsubscribe from the event

Returns

this

The current instance of the SoundManager for easy chaining


on()

ts
on<K>(
   event: Key<K, SoundManagerEvents>,
   listener: Listener<K, SoundManagerEvents>,
   ctx?: any): this;

Subscribes an event listener to the SoundManager.

Type Parameters

Type Parameter
K

Parameters

ParameterTypeDescription
eventKey<K, SoundManagerEvents>The event to subscribe the listener to
listenerListener<K, SoundManagerEvents>The callback function to call when the event occurs
ctx?anyThe this context to apply to the listener when it is called

Returns

this

The current instance of the SoundManager for easy chaining


once()

ts
once<K>(
   event: Key<K, SoundManagerEvents>,
   listener: Listener<K, SoundManagerEvents>,
   ctx?: any): this;

Subscribes an event listener to the SoundManager for a single invocation.

Type Parameters

Type Parameter
K

Parameters

ParameterTypeDescription
eventKey<K, SoundManagerEvents>The event to subscribe the listener to
listenerListener<K, SoundManagerEvents>The callback function to call when the event occurs
ctx?anyThe this context to apply to the listener when it is called

Returns

this

The current instance of the SoundManager for easy chaining


play()

ts
play(sound:
  | "Fast"
  | "Gong"
  | "Loud"
  | "Ping"
  | "Soft"
  | "Eager"
  | "Gentle"
  | "Subtle"
  | "Urgent"
  | "Classic"
  | "General"
  | "Sending"
  | "Complete"
  | "Positive"
  | "SoftFast"
  | "ShortFast"
  | "ShortSlow"
  | "FastUrgent"
  | "SlowUrgent"
  | "UrgentLoud"
  | "UrgentSoft"
  | "GeneralSoft"
  | "PositiveSlow"
  | "ImportantFast"): void;

Plays the specified notification sound if possible.

Parameters

ParameterTypeDescription
sound| "Fast" | "Gong" | "Loud" | "Ping" | "Soft" | "Eager" | "Gentle" | "Subtle" | "Urgent" | "Classic" | "General" | "Sending" | "Complete" | "Positive" | "SoftFast" | "ShortFast" | "ShortSlow" | "FastUrgent" | "SlowUrgent" | "UrgentLoud" | "UrgentSoft" | "GeneralSoft" | "PositiveSlow" | "ImportantFast"The sound which is desired to be played

Returns

void


setVolume()

ts
setVolume(volume: number): this;

Sets the volume for all sounds played by the SoundManager.

Parameters

ParameterTypeDescription
volumenumberA double between 0 and 1 which represents the desired volume

Returns

this

The current instance of the SoundManager for easy chaining


unmute()

ts
unmute(): SoundManager;

Restores the volume to its level prior to being muted.

Returns

SoundManager

The current instance of the SoundManager for easy chaining