Constructor

new Video(game, key, url)

A Video object that takes a previously loaded Video from the Phaser Cache and handles playback of it.

Alternatively it takes a getUserMedia feed from an active webcam and streams the contents of that to
the Video instead (see startMediaStream method)

The video can then be applied to a Sprite as a texture. If multiple Sprites share the same Video texture and playback
changes (i.e. you pause the video, or seek to a new time) then this change will be seen across all Sprites simultaneously.

Due to a bug in IE11 you cannot play a video texture to a Sprite in WebGL. For IE11 force Canvas mode.

If you need each Sprite to be able to play a video fully independently then you will need one Video object per Sprite.
Please understand the obvious performance implications of doing this, and the memory required to hold videos in RAM.

On some mobile browsers such as iOS Safari, you cannot play a video until the user has explicitly touched the screen.
This works in the same way as audio unlocking. Phaser will handle the touch unlocking for you, however unlike with audio
it's worth noting that every single Video needs to be touch unlocked, not just the first one. You can use the changeSource
method to try and work around this limitation, but see the method help for details.

Small screen devices, especially iPod and iPhone will launch the video in its own native video player,
outside of the Safari browser. There is no way to avoid this, it's a device imposed limitation.

This signal is dispatched if when asking for permission to use the webcam no response is given within a the Video.timeout limit.
This may be because the user has picked Not now in the permissions window, or there is a delay in establishing the LocalMediaStream.

retryInterval : integer

retryLimit : integer

When starting playback of a video Phaser will monitor its readyState using a setTimeout call.
The setTimeout happens once every Video.retryInterval ms. It will carry on monitoring the video
state in this manner until the retryLimit is reached and then abort.

A snapshot grabbed from the video. This is initially black. Populate it by calling Video.grab().
When called the BitmapData is updated with a grab taken from the current video playing or active video stream.
If Phaser has been compiled without BitmapData support this property will always be null.

Returns

On some mobile browsers you cannot play a video until the user has explicitly touched the video to allow it.
Phaser handles this via the setTouchLock method. However if you have 3 different videos, maybe an "Intro", "Start" and "Game Over"
split into three different Video objects, then you will need the user to touch-unlock every single one of them.

You can avoid this by using just one Video object and simply changing the video source. Once a Video element is unlocked it remains
unlocked, even if the source changes. So you can use this to your benefit to avoid forcing the user to 'touch' the video yet again.

As you'd expect there are limitations. So far we've found that the videos need to be in the same encoding format and bitrate.
This method will automatically handle a change in video dimensions, but if you try swapping to a different bitrate we've found it
cannot render the new video on iOS (desktop browsers cope better).

When the video source is changed the video file is requested over the network. Listen for the onChangeSource signal to know
when the new video has downloaded enough content to be able to be played. Previous settings such as the volume and loop state
are adopted automatically by the new video.

Parameters

Name

Type

Argument

Default

Description

src

string

The new URL to change the video.src to.

autoplay

boolean

<optional>

true

Should the video play automatically after the source has been updated?

Returns

Creates a new Video element from the given Blob. The Blob must contain the video data in the correct encoded format.
This method is typically called by the Phaser.Loader and Phaser.Cache for you, but is exposed publicly for convenience.

removeVideoElement()

render()

If the game is running in WebGL this will push the texture up to the GPU if it's dirty.
This is called automatically if the Video is being used by a Sprite, otherwise you need to remember to call it in your render function.
If you wish to suppress this functionality set Video.disableTextureUpload to true.

Instead of playing a video file this method allows you to stream video data from an attached webcam.

As soon as this method is called the user will be prompted by their browser to "Allow" access to the webcam.
If they allow it the webcam feed is directed to this Video. Call Video.play to start the stream.

If they block the webcam the onError signal will be dispatched containing the NavigatorUserMediaError
or MediaStreamError event.

You can optionally set a width and height for the stream. If set the input will be cropped to these dimensions.
If not given then as soon as the stream has enough data the video dimensions will be changed to match the webcam device.
You can listen for this with the onChangeSource signal.

Parameters

Name

Type

Argument

Default

Description

captureAudio

boolean

<optional>

false

Controls if audio should be captured along with video in the video stream.

width

integer

<optional>

The width is used to create the video stream. If not provided the video width will be set to the width of the webcam input source.

height

integer

<optional>

The height is used to create the video stream. If not provided the video height will be set to the height of the webcam input source.

If you only wish to pause playback of the video, to resume at a later time, use Video.paused = true instead.
If the video hasn't finished downloading calling Video.stop will not abort the download. To do that you need to
call Video.destroy instead.

If you are using a video stream from a webcam then calling Stop will disconnect the MediaStream session and disable the webcam.

Returns

unlock()

Enables the video on mobile devices, usually after the first touch.
If the SoundManager hasn't been unlocked then this will automatically unlock that as well.
Only one video can be pending unlock at any one time.