PokéRogue
    Preparing search index...

    HTML5AudioSound is the HTML5 Audio API implementation of a sound within Phaser.

    It is used automatically by the HTML5AudioSoundManager when the Web Audio API is unavailable, typically in environments that do not support it or where it has been disabled. Unlike the WebAudioSound class, HTML5AudioSound relies on native <audio> elements for playback, which means it has more limited capabilities, such as no support for audio panning.

    Each sound maintains a pool of HTMLAudioElement tags loaded via Loader.audio. Because HTML5 Audio cannot share a single element across simultaneous playbacks, you must load multiple instances of the asset if you want to play the same sound more than once at the same time.

    You do not create instances of this class directly. Instead, use this.sound.add(key) from within a Scene, which will return the correct sound type based on the audio system in use.

    Hierarchy (View Summary)

    Index

    Reference to an HTML5 Audio tag used for playing sound.

    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.

    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.

    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.

    pan: number

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

    Has no audible effect on HTML5 Audio Sound, but still generates the PAN Event.

    pendingRemove: boolean

    Flag indicating if destroy method was called on this sound.

    previousTime: number

    Audio tag's playback position recorded on previous update method call. Set to 0 if sound is not playing.

    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 audio's playback speed.

    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.

    startTime: number

    Timestamp as generated by the Request Animation Frame or SetTimeout representing the time at which the delayed sound playback should start. Set to 0 if sound playback is not delayed.

    An array containing all HTML5 Audio tags that could be used for individual sound playback. Number of instances depends on the config value passed to the Loader#audio method call, default is 1.

    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 have 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).

    • 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

      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

      Whether the marker was added successfully.

    • Method used internally for applying config values to some of the sound properties.

      Returns void

    • This method is used internally to update the playback rate of this sound.

      Returns void

    • Calls Phaser.Sound.BaseSound#destroy method and cleans up all HTML5 Audio related resources.

      Returns void

    • 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

      true if the event had listeners, else false.

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

      Returns (string | symbol)[]

      undefined

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

      Parameters

      • event: string | symbol

        The event name.

      Returns number

      The number of listeners.

    • Return the listeners registered for a given event.

      Parameters

      • event: string | symbol

        The event name.

      Returns Function[]

      The registered listeners.

    • 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

      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

      this.

    • Method used internally by sound manager for pausing sound if Phaser.Sound.HTML5AudioSoundManager#pauseOnBlur is set to true.

      Returns void

    • Add a one-time listener for a given event. The listener is automatically removed the first time the event is emitted, so it will never be called more than once.

      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

      this.

    • Method used internally by sound manager for resuming sound if Phaser.Sound.HTML5AudioSoundManager#pauseOnBlur is set to true.

      Returns void

    • Pauses the sound.undefined

      Returns boolean

      Whether the sound was paused successfully.

    • This method is used internally to pick and play the next available audio tag.undefined

      Returns boolean

      Whether the sound was assigned an audio tag successfully.

    • This method performs the audio tag pooling logic. It first looks for unused audio tag to assign to this sound object. If there are no unused audio tags, based on HTML5AudioSoundManager#override property value, it looks for sound with most advanced playback and hijacks its audio tag or does nothing.undefined

      Returns boolean

      Whether the sound was assigned an audio tag successfully.

    • 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. For HTML5 Audio this also requires creating multiple audio instances when loading the audio files.

      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

      Whether the sound started playing successfully.

    • Method used for playing audio tag and catching possible exceptions thrown from rejected Promise returned from play method call.

      Returns void

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

      Parameters

      • Optionalevent: string | symbol

        The event name.

      Returns this

      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

      this.

    • Removes a marker from the sound.

      Parameters

      • markerName: string

        The name of the marker to remove.

      Returns SoundMarker | null

      Removed marker object or 'null' if there was no marker with provided name.

    • Method used internally to reset sound state, usually when stopping sound or when hijacking audio tag from another sound.

      Returns void

    • Method used internally for resetting values of some of the config properties.

      Returns void

    • Resumes the sound.undefined

      Returns boolean

      Whether the sound was resumed successfully.

    • 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

      This Sound instance.

    • Sets the loop state of this Sound.

      Parameters

      • value: boolean

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

      Returns HTML5AudioSound

      This Sound instance.

    • Sets the muted state of this Sound.

      Parameters

      • value: boolean

        true to mute this sound, false to unmute it.

      Returns this

      This Sound instance.

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

      Has no audible effect on HTML5 Audio Sound, but still generates the PAN Event.

      Parameters

      • value: number

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

      Returns this

      This Sound instance.

    • 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 audio's playback speed.

      Parameters

      • value: number

        The playback rate of this Sound.

      Returns this

      This Sound instance.

    • Seeks to a specific point in this sound.

      Parameters

      • value: number

        The point in the sound to seek to, in seconds.

      Returns this

      This Sound instance.

    • Sets the volume of this Sound.

      Parameters

      • value: number

        The volume of the sound. A value between 0 (silence) and 1 (full volume).

      Returns this

      This Sound instance.

    • Removes all listeners from this EventEmitter. This method is called automatically by the Scene Systems when the parent Scene shuts down, ensuring that all event bindings are cleared and no stale references remain.

      Returns void

    • Stop playing this sound.undefined

      Returns boolean

      Whether the sound was stopped successfully.

    • This method is used internally to stop and release the current audio tag.

      Returns void

    • Update method called automatically by sound manager on every game step.

      Parameters

      • time: number

        The current timestamp as generated by the Request Animation Frame or SetTimeout.

      Returns void

    • Updates a previously added marker with new values from the provided marker object.

      Parameters

      • marker: SoundMarker

        Marker object with updated values.

      Returns boolean

      Whether the marker was updated successfully.

    • This method is used internally to update the mute setting of this sound.

      Returns void

    • This method is used internally to update the volume of this sound.

      Returns void