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

Properties

pending: Set<any>

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

thumbs: Map<string, string>

A mapping of base64 video thumbnail images

locked: boolean

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

#youTubeReady: Promise<any>

Store a Promise while the YouTube API is initializing.

#youTubeRegex: RegExp = ...

The YouTube URL regex.

Methods

  • Return the HTML element which provides the source for a loaded texture.

    Parameters

    • mesh: any

      The rendered mesh

    Returns HTMLImageElement | HTMLVideoElement

    The source HTML element

  • Get the video element source corresponding to a Sprite or SpriteMesh.

    Parameters

    • object: any

      The PIXI source

    Returns HTMLVideoElement

    The source video element or null

  • Clone a video texture so that it can be played independently of the original base texture.

    Parameters

    • source: HTMLVideoElement

      The video element source

    Returns Promise<Texture>

    An unlinked PIXI.Texture which can be played independently

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

    Parameters

    • video: HTMLElement

      The VIDEO element to play

    • Optional options: {
          playing: boolean;
          loop: boolean;
          offset: number;
          volume: number;
      } = {}

      Additional options for modifying video playback

      • playing: boolean

        Should the video be playing? Otherwise, it will be paused

      • loop: boolean

        Should the video loop?

      • offset: number

        A specific timestamp between 0 and the video duration to begin playback

      • volume: number

        Desired volume level of the video's audio channel (if any)

    Returns Promise<any>

  • Stop a single video source

    Parameters

    • video: HTMLElement

      The VIDEO element to stop

    Returns void

  • 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.

    Returns void

  • 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

    • event: Event

      The mouse-move event which enables playback

    Returns void

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

    Parameters

    • src: string

      The source video URL

    • options: object

      Thumbnail creation options, including width and height

    Returns Promise<string>

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

  • Lazily-load the YouTube API and retrieve a Player instance for a given iframe.

    Parameters

    Returns Promise<Player>

  • Retrieve a YouTube video ID from a URL.

    Parameters

    • url: string

      The URL.

    Returns string

  • Take a URL to a YouTube video and convert it into a URL suitable for embedding in a YouTube iframe.

    Parameters

    • url: string

      The URL to convert.

    • vars: object = {}

      YouTube player parameters.

    Returns string

    The YouTube embed URL.

  • Test a URL to see if it points to a YouTube video.

    Parameters

    • url: string = ""

      The URL to test.

    Returns boolean

  • Inject the YouTube API into the page.

    Returns Promise<any>

    A Promise that resolves when the API has initialized.

  • Check if a source has a video extension.

    Parameters

    • src: string

      The source.

    Returns boolean

    If the source has a video extension or not.