Options
All
  • Public
  • Public/Protected
  • All
Menu

The Sound object allows games built in Excalibur to load audio components, from soundtracks to sound effects. Sound is an Loadable which means it can be passed to a Loader to pre-load before a game or level.

Hierarchy

Implements

Index

Constructors

  • new Sound(...paths: string[]): Sound

Properties

data: AudioBuffer

Data associated with a loadable

eventDispatcher: EventDispatcher<any>

Direct access to the game object event dispatcher.

logger: Util.Logger = ...

Accessors

  • get duration(): number
  • set duration(duration: number): void
  • Get the duration that this audio should play. If unset the total natural playback duration will be used.

    Returns number

  • Set the duration that this audio should play. If unset the total natural playback duration will be used.

    Note: if you seek to a specific point the duration will start from that point, for example

    If you have a 10 second clip, seek to 5 seconds, then set the duration to 2, it will play the clip from 5-7 seconds.

    Parameters

    • duration: number

    Returns void

  • get loop(): boolean
  • set loop(value: boolean): void
  • get path(): string
  • set path(val: string): void
  • get playbackRate(): number
  • set playbackRate(playbackRate: number): void
  • get volume(): number
  • set volume(value: number): void

Methods

  • decodeAudio(data: ArrayBuffer): Promise<AudioBuffer>
  • emit(eventName: string, eventObject: any): void
  • Emits a new event

    Parameters

    • eventName: string

      Name of the event to emit

    • eventObject: any

      Data associated with this event

    Returns void

  • getPlaybackPosition(trackId?: number): number
  • Return the current playback time of the playing track in seconds from the start.

    Optionally specify the track to query if multiple are playing at once.

    Parameters

    • trackId: number = 0

    Returns number

  • getTotalPlaybackDuration(): number
  • getTrackId(track: Audio): number
  • instanceCount(): number
  • isLoaded(): boolean
  • isPaused(): boolean
  • isPlaying(): boolean
  • load(): Promise<AudioBuffer>
  • off(eventName: string, handler?: ((event: any) => void)): void
  • Alias for removeEventListener. If only the eventName is specified it will remove all handlers registered for that specific event. If the eventName and the handler instance are specified only that handler will be removed.

    Parameters

    • eventName: string

      Name of the event to listen for

    • Optional handler: ((event: any) => void)

      Event handler for the thrown event

        • (event: any): void
        • Parameters

          • event: any

          Returns void

    Returns void

  • on(eventName: string, handler: ((event: any) => void)): void
  • Alias for addEventListener. You can listen for a variety of events off of the engine; see the events section below for a complete list.

    Parameters

    • eventName: string

      Name of the event to listen for

    • handler: ((event: any) => void)

      Event handler for the thrown event

        • (event: any): void
        • Parameters

          • event: any

          Returns void

    Returns void

  • once(eventName: string, handler: ((event: any) => void)): void
  • Once listens to an event one time, then unsubscribes from that event

    Parameters

    • eventName: string

      The name of the event to subscribe to once

    • handler: ((event: any) => void)

      The handler of the event that will be auto unsubscribed

        • (event: any): void
        • Parameters

          • event: any

          Returns void

    Returns void

  • pause(): void
  • play(volume?: number): Promise<boolean>
  • Play the sound, returns a promise that resolves when the sound is done playing An optional volume argument can be passed in to play the sound. Max volume is 1.0

    Parameters

    • Optional volume: number

    Returns Promise<boolean>

  • seek(position: number, trackId?: number): void
  • stop(): void
  • Stop the sound if it is currently playing and rewind the track. If the sound is not playing, rewinds the track.

    Returns void

  • wireEngine(engine: Engine): void