Skip to main content
Version: Phaser v4.0.0

HTML5AudioFile

A single audio file loaded via the HTML5 Audio API, suitable for loading by the Loader.

Unlike WebAudioFile, which uses the Web Audio API, this file type creates standard HTML Audio elements. It is used as a fallback when the Web Audio API is unavailable, or when the game is configured to use HTML5 audio exclusively. Multiple instances of the audio element can be created to allow the same sound to play concurrently without interruption.

These are created when you use the Phaser.Loader.LoaderPlugin#audio method and are not typically created directly.

For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#audio.

Constructor

new HTML5AudioFile(loader, key, [urlConfig], [audioConfig])

Parameters

nametypeoptionaldescription
loaderPhaser.Loader.LoaderPluginNoA reference to the Loader that is responsible for this file.
keystring | Phaser.Types.Loader.FileTypes.AudioFileConfigNoThe key to use for this file, or a file configuration object.
urlConfigstringYesThe absolute or relative URL to load this file from.
audioConfigobjectYesThe AudioContext config object.

Scope: static

Extends

Phaser.Loader.File

Source: src/loader/filetypes/HTML5AudioFile.js#L14
Since: 3.0.0

Inherited Methods

From Phaser.Loader.File:


Public Methods

load

<instance> load()

Description:

Called by the Loader, starts the actual file downloading. Creates one or more HTML Audio elements (based on the configured instance count) and assigns the source URL to each. During the load the methods onLoad, onError and onProgress are called, based on the Audio element events. You shouldn't normally call this method directly, it's meant to be invoked by the Loader.

Overrides: Phaser.Loader.File#load

Source: src/loader/filetypes/HTML5AudioFile.js#L135
Since: 3.0.0


onError

<instance> onError()

Description:

Called if the file errors while loading.

Overrides: Phaser.Loader.File#onError

Source: src/loader/filetypes/HTML5AudioFile.js#L90
Since: 3.0.0


onLoad

<instance> onLoad()

Description:

Called when the file finishes loading.

Overrides: Phaser.Loader.File#onLoad

Source: src/loader/filetypes/HTML5AudioFile.js#L72
Since: 3.0.0


onProgress

<instance> onProgress()

Description:

Called when an individual Audio element fires its canplaythrough event, indicating it is ready to play.

Overrides: Phaser.Loader.File#onProgress

Fires: Phaser.Loader.Events#event:FILE_PROGRESS

Source: src/loader/filetypes/HTML5AudioFile.js#L109
Since: 3.0.0


Inherited Members

From Phaser.Loader.File: