gameforge - v0.1.12
    Preparing search index...

    Class SoundLibrary

    Manages the playback of sounds. This is the main class for PixiJS Sound. If you're using the browser-based bundled this is PIXI.sound. Otherwise, you can do this:

    import { sound } from '@pixi/sound';

    // sound is an instance of SoundLibrary
    sound.add('my-sound', 'path/to/file.mp3');
    sound.play('my-sound');
    Index

    Constructors

    Accessors

    • get context(): IMediaContext

      The global context to use.

      Returns IMediaContext

    • get disableAutoPause(): boolean

      This disables auto-pause all playback when the window blurs (WebAudio only). This is helpful to keep from playing sounds when the user switches tabs. However, if you're running content within an iframe, this may be undesirable and you should disable (set to true) this behavior.

      Returns boolean

      false
      
    • set disableAutoPause(autoPause: boolean): void

      Parameters

      • autoPause: boolean

      Returns void

    • get filtersAll(): PixiSound.Filter[]

      Apply filters to all sounds. Can be useful for setting global planning or global effects. Only supported with WebAudio.

      Returns PixiSound.Filter[]

      import { sound, filters } from '@pixi/sound';
      // Adds a filter to pan all output left
      sound.filtersAll = [
      new filters.StereoFilter(-1)
      ];
    • set filtersAll(filtersAll: PixiSound.Filter[]): void

      Parameters

      Returns void

    • get speedAll(): number

      Set the global speed for all sounds. To set per-sound speed see SoundLibrary#speed.

      Returns number

    • set speedAll(speed: number): void

      Parameters

      • speed: number

      Returns void

    • get supported(): boolean

      true if WebAudio is supported on the current browser.

      Returns boolean

    • get useLegacy(): boolean

      Do not use WebAudio, force the use of legacy. This must be called before loading any files.

      Returns boolean

    • set useLegacy(legacy: boolean): void

      Parameters

      • legacy: boolean

      Returns void

    • get volumeAll(): number

      Set the global volume for all sounds. To set per-sound volume see SoundLibrary#volume.

      Returns number

    • set volumeAll(volume: number): void

      Parameters

      • volume: number

      Returns void

    Methods

    • Adds a new sound by alias.

      Parameters

      • alias: string

        The sound alias reference.

      • options: string | ArrayBuffer | Sound | Options | HTMLAudioElement | AudioBuffer

        Either the path or url to the source file. or the object of options to use.

      Returns Sound

      Instance of the Sound object.

    • Adds multiple sounds at once.

      Parameters

      • map: SoundSourceMap

        Map of sounds to add, the key is the alias, the value is the string, ArrayBuffer, AudioBuffer, HTMLAudioElement or the list of options (see Options for full options).

      • OptionalglobalOptions: Options

        The default options for all sounds. if a property is defined, it will use the local property instead.

      Returns SoundMap

      Instance to the Sound object.

    • Closes the sound library. This will release/destroy the AudioContext(s). Can be used safely if you want to initialize the sound library later. Use init method.

      Returns this

    • Get the length of a sound in seconds.

      Parameters

      • alias: string

        The sound alias reference.

      Returns number

      The current duration in seconds.

    • Checks if a sound by alias exists.

      Parameters

      • alias: string

        Check for alias.

      • Optionalassert: boolean

        Whether enable console.assert.

      Returns boolean

      true if the sound exists.

    • Find a sound by alias.

      Parameters

      • alias: string

        The sound alias reference.

      Returns Sound

      Sound object.

    • Re-initialize the sound library, this will recreate the AudioContext. If there's a hardware-failure call close and then init.

      Returns this

      Sound instance

    • Convenience function to check to see if any sound is playing.

      Returns boolean

      true if any sound is currently playing.

    • Mutes all playing sounds.

      Returns this

      Instance for chaining.

    • Pauses a sound.

      Parameters

      • alias: string

        The sound alias reference.

      Returns Sound

      Sound object.

    • Pauses any playing sounds.

      Returns this

      Instance for chaining.

    • Plays a sound.

      Parameters

      • alias: string

        The sound alias reference.

      • Optionaloptions: string | CompleteCallback | PlayOptions

        The options or callback when done.

      Returns IMediaInstance | Promise<IMediaInstance>

      The sound instance, this cannot be reused after it is done playing. Returns a Promise if the sound has not yet loaded.

    • Removes a sound by alias.

      Parameters

      • alias: string

        The sound alias reference.

      Returns this

      Instance for chaining.

    • Stops and removes all sounds. They cannot be used after this.

      Returns this

      Instance for chaining.

    • Resumes a sound.

      Parameters

      • alias: string

        The sound alias reference.

      Returns Sound

      Instance for chaining.

    • Resumes any sounds.

      Returns this

      Instance for chaining.

    • Get or set the speed for a sound.

      Parameters

      • alias: string

        The sound alias reference.

      • Optionalspeed: number

        Optional current speed to set.

      Returns number

      The current speed.

    • Stops a sound.

      Parameters

      • alias: string

        The sound alias reference.

      Returns Sound

      Sound object.

    • Stops all sounds.

      Returns this

      Instance for chaining.

    • Toggle muted property for all sounds.

      Returns boolean

      true if all sounds are muted.

    • Toggle paused property for all sounds.

      Returns boolean

      true if all sounds are paused.

    • Unmutes all playing sounds.

      Returns this

      Instance for chaining.

    • Get or set the volume for a sound.

      Parameters

      • alias: string

        The sound alias reference.

      • Optionalvolume: number

        Optional current volume to set.

      Returns number

      The current volume.