Phaser API Documentation

  Version: 
play([loop], [markerIn], [markerOut])

Description:

Starts this video playing.

If the video is already playing, or has been queued to play with changeSource then this method just returns.

Videos can only autoplay if the browser has been unlocked. This happens if you have interacted with the browser, i.e. by clicking on it or pressing a key, or due to server settings. The policies that control autoplaying are vast and vary between browser. You can read more here: https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide

If your video doesn't contain any audio, then set the noAudio parameter to true when the video is loaded, and it will often allow the video to play immediately:

preload () {
  this.load.video('pixar', 'nemo.mp4', 'loadeddata', false, true);
}

The 5th parameter in the load call tells Phaser that the video doesn't contain any audio tracks. Video without audio can autoplay without requiring a user interaction. Video with audio cannot do this unless it satisfies the browsers MEI settings. See the MDN Autoplay Guide for details.

If you need audio in your videos, then you'll have to consider the fact that the video cannot start playing until the user has interacted with the browser, into your game flow.

Parameters:

name type arguments Default description
loop boolean <optional> false

Should the video loop automatically when it reaches the end? Please note that not all browsers support seamless video looping for all encoding formats.

markerIn number <optional>

Optional in marker time, in seconds, for playback of a sequence of the video.

markerOut number <optional>

Optional out marker time, in seconds, for playback of a sequence of the video.

Returns:
Description:

This Video Game Object for method chaining.

Since: 3.20.0