Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AudioSystem

Hierarchy

  • AudioSystem

Index

Constructors

constructor

  • A wrapper around web audio for games.

    constructor

    Returns AudioSystem

Properties

Private _currentMusic

_currentMusic: any

Private _fadeMusic

_fadeMusic: any

Private _initialized

_initialized: any

Private _musicFade

_musicFade: any

Private _musicFaderGain

_musicFaderGain: any

Private _musicLoopStart

_musicLoopStart: any

Private _muted

_muted: any

Private _playingSounds

_playingSounds: any

A list of all sound effects currently being played. If a sound effect is not looping (which is likely typical), it will be removed from this list when it completes. This data structure allows us to pause all sound effects at the same time.

Private _soundEffectIdGenerator

_soundEffectIdGenerator: any

Used to give all playing sound effects unique ids.

Private _sounds

_sounds: any

Private _volumeFaderGain

_volumeFaderGain: any

context

context: AudioContext

Private currentMusicId

currentMusicId: any

fadeMusic

fadeMusic: boolean

musicFadeSeconds

musicFadeSeconds: number

Methods

Private _createPlayingSound

  • _createPlayingSound(id: any, loop?: any, startOffset?: any, doneCallback?: any): any
  • Parameters

    • id: any
    • Optional loop: any
    • Optional startOffset: any
    • Optional doneCallback: any

    Returns any

Private _createSoundEffectId

  • _createSoundEffectId(): any
  • Returns any

Private _removePlayingSound

  • _removePlayingSound(id: any): any
  • Removes a sound from our list of currently-being-played sound effects.

    Parameters

    • id: any

    Returns any

    The sound just removed.

addSound

  • addSound(sound: Sound): void
  • Registers a sound for later playback.

    Parameters

    • sound: Sound

      The sound.

    Returns void

fadeOutMusic

  • fadeOutMusic(newMusicId: string): void
  • Parameters

    • newMusicId: string

    Returns void

getCurrentMusic

  • getCurrentMusic(): string
  • Returns the ID of the current music being played.

    see

    playMusic

    see

    stopMusic

    Returns string

    The current music's ID.

init

  • init(): void
  • Initializes the audio system.

    Returns void

isInitialized

  • isInitialized(): boolean
  • Returns whether the audio system initialized properly. This will return false if the user's browser does not support the web audio API.

    Returns boolean

    Whether the sound system is initialized

pauseAll

  • pauseAll(): void
  • Pauses all music and sound effects.

    see

    resumeAll

    Returns void

playMusic

  • playMusic(id: string, loop?: boolean): void
  • Plays a specific sound as background music. Only one "music" can play at a time, as opposed to "sounds," of which multiple can be playing at one time.

    see

    stopMusic

    Parameters

    • id: string

      The ID of the resource to play as music. If this is null, the current music is stopped but no new music is started.

    • Optional loop: boolean

      Whether the music should loop.

    Returns void

playSound

  • playSound(id: string, loop?: boolean, doneCallback?: Function): number
  • Plays the sound with the given ID.

    see

    stopSound

    Parameters

    • id: string

      The ID of the resource to play.

    • Optional loop: boolean

      Whether the music should loop. Defaults to false.

    • Optional doneCallback: Function

      An optional callback to call when the sound completes. This callback will receive the returned numeric ID as a parameter. This parameter is ignored if loop is true.

    Returns number

    An ID for the playing sound. This can be used to stop a looping sound via stopSound(id).

resumeAll

  • resumeAll(): void
  • Resumes all music and sound effects.

    see

    pauseAll

    Returns void

stopMusic

  • stopMusic(pause?: boolean): void
  • Stops the currently playing music, if any.

    see

    playMusic

    Parameters

    • Optional pause: boolean

      If true, the music is only paused; otherwise, native resources are freed and the music cannot be resumed.

    Returns void

stopSound

  • stopSound(id: number): boolean
  • Stops a playing sound, by ID.

    see

    playSound

    Parameters

    • id: number

      The sound effect to stop.

    Returns boolean

    Whether the sound effect was stopped. This will be false if the sound effect specified is no longer playing.

toggleMuted

  • toggleMuted(): boolean
  • Returns boolean

Generated using TypeDoc