phaser - v4.0.0-rc.4
    Preparing search index...

    Web Audio API implementation of the sound.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    audioBuffer: AudioBuffer

    Audio buffer containing decoded data of the audio asset to be played.

    currentMarker: SoundMarker

    Currently playing marker. 'null' if whole sound is playing.

    detune: number

    The detune value of this Sound, given in cents. The range of the value is -1200 to 1200, but we recommend setting it to 50.

    duration: number

    A value representing the duration, in seconds. It could be total sound duration or a marker duration.

    hasEnded: boolean

    Used for keeping track when sound source playback has ended so its state can be updated accordingly.

    hasLooped: boolean

    Used for keeping track when sound source has looped so its state can be updated accordingly.

    isPaused: boolean

    Flag indicating if sound is currently paused.

    isPlaying: boolean

    Flag indicating if sound is currently playing.

    key: string

    Asset key for the sound.

    loop: boolean

    Flag indicating whether or not the sound or current sound marker will loop.

    loopSource: AudioBufferSourceNode

    A reference to a second audio source used for gapless looped playback.

    loopTime: number

    The time at which the sound loop source should actually start playback.

    Based on BaseAudioContext.currentTime value.

    Local reference to the sound manager.

    markers: { [key: string]: SoundMarker }

    Object containing markers definitions.

    mute: boolean

    Boolean indicating whether the sound is muted or not. Gets or sets the muted state of this sound.

    muteNode: GainNode

    Gain node responsible for controlling this sound's muting.

    pan: number

    Gets or sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan).

    Always returns zero on iOS / Safari as it doesn't support the stereo panner node.

    pannerNode: StereoPannerNode

    Panner node responsible for controlling this sound's pan.

    Doesn't work on iOS / Safari.

    pendingRemove: boolean

    Flag indicating if destroy method was called on this sound.

    playTime: number

    The time at which the sound should have started playback from the beginning.

    Treat this property as read-only.

    Based on BaseAudioContext.currentTime value.

    rate: number

    Rate at which this Sound will be played. Value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed and 2.0 doubles the audios playback speed.

    rateUpdates: any[]

    An array where we keep track of all rate updates during playback.

    Treat this property as read-only.

    Array of object types: { time: number, rate: number }

    seek: number

    Property representing the position of playback for this sound, in seconds. Setting it to a specific value moves current playback to that position. The value given is clamped to the range 0 to current marker duration. Setting seek of a stopped sound has no effect.

    source: AudioBufferSourceNode

    A reference to an audio source node used for playing back audio from audio data stored in Phaser.Sound.WebAudioSound#audioBuffer.

    spatialNode: PannerNode

    The Stereo Spatial Panner node.

    spatialSource: Vector2Like

    If the Spatial Panner node has been set to track a vector or Game Object, this retains a reference to it.

    startTime: number

    The time at which the sound source should have actually started playback.

    Treat this property as read-only.

    Based on BaseAudioContext.currentTime value.

    totalDuration: number

    The total duration of the sound in seconds.

    totalRate: number

    A property that holds the value of sound's actual playback rate, after its rate and detune values has been combined with global rate and detune values.

    volume: number

    Gets or sets the volume of this sound, a value between 0 (silence) and 1 (full volume).

    volumeNode: GainNode

    Gain node responsible for controlling this sound's volume.

    x: number

    Sets the x position of this Sound in Spatial Audio space.

    This only has any effect if the sound was created with a SpatialSoundConfig object.

    Also see the WebAudioSoundManager.setListenerPosition method.

    If you find that the sound becomes too quiet, too quickly, as it moves away from the listener, then try different refDistance property values when configuring the spatial sound.

    y: number

    Sets the y position of this Sound in Spatial Audio space.

    This only has any effect if the sound was created with a SpatialSoundConfig object.

    Also see the WebAudioSoundManager.setListenerPosition method.

    If you find that the sound becomes too quiet, too quickly, as it moves away from the listener, then try different refDistance property values when configuring the spatial sound.

    Methods

    • Add a listener for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • fn: Function

        The listener function.

      • Optionalcontext: any

        The context to invoke the listener with. Default this.

      Returns this

    • Adds a marker into the current sound. A marker is represented by name, start time, duration, and optionally config object. This allows you to bundle multiple sounds together into a single audio file and use markers to jump between them for playback.

      Parameters

      Returns boolean

    • This method is only used internally and it creates a looping buffer source.

      Returns void

    • This method is only used internally and it creates a buffer source.

      Returns AudioBufferSourceNode

    • Calls each of the listeners registered for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • ...args: any[]

        Additional arguments that will be passed to the event handler.

      Returns boolean

    • Return an array listing the events for which the emitter has registered listeners.

      Returns (string | symbol)[]

    • Method used internally for calculating current playback time of a playing sound.

      Returns void

    • Method used internally for calculating the time at witch the loop source should start playing.

      Returns void

    • Return the number of listeners listening to a given event.

      Parameters

      • event: string | symbol

        The event name.

      Returns number

    • Return the listeners registered for a given event.

      Parameters

      • event: string | symbol

        The event name.

      Returns Function[]

    • Remove the listeners of a given event.

      Parameters

      • event: string | symbol

        The event name.

      • Optionalfn: Function

        Only remove the listeners that match this function.

      • Optionalcontext: any

        Only remove the listeners that have this context.

      • Optionalonce: boolean

        Only remove one-time listeners.

      Returns this

    • Add a listener for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • fn: Function

        The listener function.

      • Optionalcontext: any

        The context to invoke the listener with. Default this.

      Returns this

    • Add a one-time listener for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • fn: Function

        The listener function.

      • Optionalcontext: any

        The context to invoke the listener with. Default this.

      Returns this

    • Play this sound, or a marked section of it.

      It always plays the sound from the start. If you want to start playback from a specific time you can set 'seek' setting of the config object, provided to this call, to that value.

      If you want to play the same sound simultaneously, then you need to create another instance of it and play that Sound.

      Parameters

      • OptionalmarkerName: string | SoundConfig

        If you want to play a marker then provide the marker name here. Alternatively, this parameter can be a SoundConfig object. Default ''.

      • Optionalconfig: SoundConfig

        Optional sound config object to be applied to this marker or entire sound if no marker name is provided. It gets memorized for future plays of current section of the sound.

      Returns boolean

    • Remove all listeners, or those of the specified event.

      Parameters

      • Optionalevent: string | symbol

        The event name.

      Returns this

    • Remove the listeners of a given event.

      Parameters

      • event: string | symbol

        The event name.

      • Optionalfn: Function

        Only remove the listeners that match this function.

      • Optionalcontext: any

        Only remove the listeners that have this context.

      • Optionalonce: boolean

        Only remove one-time listeners.

      Returns this

    • Sets the detune value of this Sound, given in cents. The range of the value is -1200 to 1200, but we recommend setting it to 50.

      Parameters

      • value: number

        The range of the value is -1200 to 1200, but we recommend setting it to 50.

      Returns this

    • Sets the loop state of this Sound.

      Parameters

      • value: boolean

        true to loop this sound, false to not loop it.

      Returns this

    • Sets the muted state of this Sound.

      Parameters

      • value: boolean

        true to mute this sound, false to unmute it.

      Returns this

    • Sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan).

      Note: iOS / Safari doesn't support the stereo panner node.

      Parameters

      • value: number

        The pan of the sound. A value between -1 (full left pan) and 1 (full right pan).

      Returns this

    • Sets the playback rate of this Sound.

      For example, a value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed and 2.0 doubles the audios playback speed.

      Parameters

      • value: number

        The playback rate at of this Sound.

      Returns this

    • Seeks to a specific point in this sound.

      Parameters

      • value: number

        The point in the sound to seek to.

      Returns this

    • Sets the volume of this Sound.

      Parameters

      • value: number

        The volume of the sound.

      Returns this

    • This method is only used internally and it stops and removes a buffer source.

      Returns void

    • This method is only used internally and it stops and removes a looping buffer source.

      Returns void