Manages all the sounds.

Hierarchy

  • SoundManager

Constructors

Properties

Accessors

Methods

Constructors

Properties

_volume: number = VOLUME
audios: HTMLAudioElement[] = []

Audio elements playing or pending to play. Finished audios will be removed automatically.

Accessors

Methods

  • Creates an audio element and adds it to the audios.

    Returns

    Created audio element.

    Parameters

    • file: string

      URL of the sound file.

    • Optional onFinish: (() => void)

      Callback invoked when the playback has finished.

        • (): void
        • Returns void

    • Optional onError: ((e: Error) => void)

      Callback invoked when error occurs.

        • (e: Error): void
        • Parameters

          • e: Error

          Returns void

    Returns HTMLAudioElement

  • Plays the sound.

    Returns

    Promise that resolves when the audio is ready to play, rejects when error occurs.

    Parameters

    • audio: HTMLAudioElement

      An audio element.

    Returns Promise<void>

Generated using TypeDoc