Video#changeSource()

changeSource(src, autoplay) → {Phaser.Video}

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

This Video object for method chaining.

Source code: gameobjects/Video.js (Line 954)
doc_phaser
2017-02-14 11:19:21
Comments
Leave a Comment

Please login to continue.