Phaser API Documentation

  Version: 
video(key, [urls], [loadEvent], [asBlob], [noAudio], [xhrSettings])

Description:

Adds a Video file, or array of video files, to the current load queue.

You can call this method from within your Scene's preload, along with any other files you wish to load:

function preload ()
{
    this.load.video('intro', [ 'video/level1.mp4', 'video/level1.webm', 'video/level1.mov' ]);
}

The file is not loaded right away. It is added to a queue ready to be loaded either when the loader starts, or if it's already running, when the next free load slot becomes available. This happens automatically if you are calling this from within the Scene's preload method, or a related callback. Because the file is queued it means you cannot use the file immediately after calling this method, but must wait for the file to complete. The typical flow for a Phaser Scene is that you load assets in the Scene's preload method and then when the Scene's create method is called you are guaranteed that all of those assets are ready for use and have been loaded.

The key must be a unique String. It is used to add the file to the global Video Cache upon a successful load. The key should be unique both in terms of files being loaded and files already present in the Video Cache. Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file then remove it from the Video Cache first, before loading a new one.

Instead of passing arguments you can pass a configuration object, such as:

this.load.video({
    key: 'intro',
    url: [ 'video/level1.mp4', 'video/level1.webm', 'video/level1.mov' ],
    asBlob: false,
    noAudio: true
});

See the documentation for Phaser.Types.Loader.FileTypes.VideoFileConfig for more details.

The URLs can be relative or absolute. If the URLs are relative the Loader.baseURL and Loader.path values will be prepended to them.

Due to different browsers supporting different video file types you should usually provide your video files in a variety of formats. mp4, mov and webm are the most common. If you provide an array of URLs then the Loader will determine which one file to load based on browser support, starting with the first in the array and progressing to the end.

Unlike most asset-types, videos do not need to be preloaded. You can create a Video Game Object and then call its loadURL method, to load a video at run-time, rather than in advance.

Note: The ability to load this type of file will only be available if the Video File type has been built into Phaser. It is available in the default build but can be excluded from custom builds.

Parameters:

name type arguments Default description
key string | Phaser.Types.Loader.FileTypes.VideoFileConfig | Array.<Phaser.Types.Loader.FileTypes.VideoFileConfig>

The key to use for this file, or a file configuration object, or array of them.

urls string | Array.<string> <optional>

The absolute or relative URL to load the video files from.

loadEvent string <optional> 'loadeddata'

The load event to listen for when not loading as a blob. Either loadeddata, canplay or canplaythrough.

asBlob boolean <optional> false

Load the video as a data blob, or stream it via the Video element?

noAudio boolean <optional> false

Does the video have an audio track? If not you can enable auto-playing on it.

xhrSettings Phaser.Types.Loader.XHRSettingsObject <optional>

An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings.

Returns:
Description:

The Loader instance.

Since: 3.20.0