VideoHelper

VideoHelper

A helper class to provide common functionality for working with HTML5 video objects A singleton instance of this class is available as game.video

Constructor

new VideoHelper()

Members

locked :boolean

A flag for whether video playback is currently locked by awaiting a user gesture

Type:
  • boolean

pending :Set

A user gesture must be registered before video playback can begin. This Set records the video elements which await such a gesture.

Type:
  • Set

thumbs :Map.<string, string>

A mapping of base64 video thumbnail images

Type:
  • Map.<string, string>

Methods

_onFirstGesture(event)

Handle the first observed user gesture We need a slight delay because unfortunately Chrome is stupid and doesn't always acknowledge the gesture fast enough.

Parameters:
Name Type Description
event Event

The mouse-move event which enables playback

awaitFirstGesture()

Register an event listener to await the first mousemove gesture and begin playback once observed A user interaction must involve a mouse click or keypress. Listen for any of these events, and handle the first observed gesture.

(async) createThumbnail(src, options) → {Promise.<string>}

Create and cache a static thumbnail to use for the video. The thumbnail is cached using the video file path or URL.

Parameters:
Name Type Description
src string

The source video URL

options object

Thumbnail creation options, including width and height

Returns:

The created and cached base64 thumbnail image, or a placeholder image if the canvas is disabled and no thumbnail can be generated.

Type
Promise.<string>

play(video)

Play a single video source If playback is not yet enabled, add the video to the pending queue

Parameters:
Name Type Description
video HTMLElement

The VIDEO element to play

stop(video)

Stop a single video source

Parameters:
Name Type Description
video HTMLElement

The VIDEO element to stop