PictureInPictureChildVideoWrapper Reference

class PictureInPictureChildVideoWrapper(videoWrapperScriptPath, video, pipChild)

The PictureInPictureChildVideoWrapper class handles providing a path to a script that defines a “site wrapper” for the original <video> (or other controls API provided by the site) to command it.

This “site wrapper” provided to PictureInPictureChildVideoWrapper is a script file that defines a class called PictureInPictureVideoWrapper and exports it. These scripts can be found under “browser/extensions/pictureinpicture/video-wrappers” as part of the Picture-In-Picture addon.

Site wrappers need to adhere to a specific interface to work properly with PictureInPictureChildVideoWrapper:

  • The “site wrapper” script must export a class called “PictureInPictureVideoWrapper”

  • Method names on a site wrapper class should match its caller’s name (i.e: PictureInPictureChildVideoWrapper.play will only call play on a site-wrapper, if available)

Create a wrapper for the original <video>

Arguments:
  • videoWrapperScriptPath (String|null) – Path to a wrapper script from the Picture-in-Picture addon. If a wrapper isn’t provided to the class, then we fallback on a default implementation for commanding the original <video>.

  • video (HTMLVideoElement) – The original <video> we want to create a wrapper class for.

  • pipChild (Object) – Reference to PictureInPictureChild class calling this function.

PictureInPictureChildVideoWrapper.destroy()

Destroys the sandbox for the site wrapper class

PictureInPictureChildVideoWrapper.formatTimestamp(aCurrentTime, aDuration)

Format a timestamp from current time and total duration, output as a string in the form ‘0:00 / 0:00’

Arguments:
  • aCurrentTime (Number) – The current time in seconds

  • aDuration (Number) – The total duration in seconds

Returns:

String – Formatted timestamp

PictureInPictureChildVideoWrapper.getCurrentTime(video)

OVERRIDABLE - calls the getCurrentTime() method defined in the site wrapper script. Runs a fallback implementation if the method does not exist or if an error is thrown while calling it. This method is meant to get the current time of a video in seconds.

Arguments:
  • video (HTMLVideoElement) – The originating video source element

Returns:

Number – Current time of the video in seconds

PictureInPictureChildVideoWrapper.getDuration(video)

OVERRIDABLE - calls the getDuration() method defined in the site wrapper script. Runs a fallback implementation if the method does not exist or if an error is thrown while calling it. This method is meant to get the current duration of a video in seconds.

Arguments:
  • video (HTMLVideoElement) – The originating video source element

Returns:

Number – Duration of the video in seconds

PictureInPictureChildVideoWrapper.getEnded(video)

OVERRIDABLE - calls the getEnded() method defined in the site wrapper script. Runs a fallback implementation if the method does not exist or if an error is thrown while calling it. This method is meant to determine if video playback or streaming has stopped.

Arguments:
  • video (HTMLVideoElement) – The originating video source element

Returns:

Boolean – Boolean value true if the video has ended, or false if still playing

PictureInPictureChildVideoWrapper.getPaused(video)

OVERRIDABLE - calls the getPaused() method defined in the site wrapper script. Runs a fallback implementation if the method does not exist or if an error is thrown while calling it. This method is meant to determine if a video is paused or not.

Arguments:
  • video (HTMLVideoElement) – The originating video source element

Returns:

Boolean – Boolean value true if paused, or false if video is still playing

PictureInPictureChildVideoWrapper.getVolume(video)

OVERRIDABLE - calls the getVolume() method defined in the site wrapper script. Runs a fallback implementation if the method does not exist or if an error is thrown while calling it. This method is meant to get the volume value of a video.

Arguments:
  • video (HTMLVideoElement) – The originating video source element

Returns:

Number – Volume of the video between 0 (muted) and 1 (loudest)

PictureInPictureChildVideoWrapper.isLive(video)

OVERRIDABLE - calls the isLive() method defined in the site wrapper script. Runs a fallback implementation if the method does not exist or if an error is thrown while calling it. This method is meant to get if the video is a live stream.

Arguments:
  • video (HTMLVideoElement) – The originating video source element

PictureInPictureChildVideoWrapper.isMuted(video, shouldMute)

OVERRIDABLE - calls the isMuted() method defined in the site wrapper script. Runs a fallback implementation if the method does not exist or if an error is thrown while calling it. This method is meant to get the mute state a video.

Arguments:
  • video (HTMLVideoElement) – The originating video source element

  • shouldMute (Boolean) – Boolean value true to mute the video, or false to unmute the video

PictureInPictureChildVideoWrapper.pause(video)

OVERRIDABLE - calls the pause() method defined in the site wrapper script. Runs a fallback implementation if the method does not exist or if an error is thrown while calling it. This method is meant to handle video behaviour when a video is paused.

Arguments:
  • video (HTMLVideoElement) – The originating video source element

PictureInPictureChildVideoWrapper.play(video)

OVERRIDABLE - calls the play() method defined in the site wrapper script. Runs a fallback implementation if the method does not exist or if an error is thrown while calling it. This method is meant to handle video behaviour when a video is played.

Arguments:
  • video (HTMLVideoElement) – The originating video source element

PictureInPictureChildVideoWrapper.removeCaptionContainerObserver(video, _callback)

OVERRIDABLE - calls the removeCaptionContainerObserver() method defined in the site wrapper script. Runs a fallback implementation if the method does not exist or if an error is thrown while calling it. This method is meant to remove any caption observers that may have been set in setCaptionContainerObserver().

Arguments:
  • video (HTMLVideoElement) – The originating video source element

  • _callback (function) – The callback function to be executed when cue changes are detected

PictureInPictureChildVideoWrapper.setCaptionContainerObserver(video, _callback)

OVERRIDABLE - calls the setCaptionContainerObserver() method defined in the site wrapper script. Runs a fallback implementation if the method does not exist or if an error is thrown while calling it. This method is meant to listen for any cue changes in a video’s caption container and execute a callback function responsible for updating the pip window’s text tracks container whenever a cue change is triggered {@see updatePiPTextTracks()}.

Arguments:
  • video (HTMLVideoElement) – The originating video source element

  • _callback (function) – The callback function to be executed when cue changes are detected

PictureInPictureChildVideoWrapper.setCurrentTime(video, position, wasPlaying)

OVERRIDABLE - calls the setCurrentTime() method defined in the site wrapper script. Runs a fallback implementation if the method does not exist or if an error is thrown while calling it. This method is meant to set the current time of a video.

Arguments:
  • video (HTMLVideoElement) – The originating video source element

  • position (Number) – The current playback time of the video

  • wasPlaying (Boolean) – True if the video was playing before seeking else false

PictureInPictureChildVideoWrapper.setMuted(video, shouldMute)

OVERRIDABLE - calls the setMuted() method defined in the site wrapper script. Runs a fallback implementation if the method does not exist or if an error is thrown while calling it. This method is meant to mute or unmute a video.

Arguments:
  • video (HTMLVideoElement) – The originating video source element

  • shouldMute (Boolean) – Boolean value true to mute the video, or false to unmute the video

PictureInPictureChildVideoWrapper.setVolume(video, volume)

OVERRIDABLE - calls the setVolume() method defined in the site wrapper script. Runs a fallback implementation if the method does not exist or if an error is thrown while calling it. This method is meant to set the volume value of a video.

Arguments:
  • video (HTMLVideoElement) – The originating video source element

  • volume (Number) – Value between 0 (muted) and 1 (loudest)

PictureInPictureChildVideoWrapper.shouldHideToggle(video)

OVERRIDABLE - calls the shouldHideToggle() method defined in the site wrapper script. Runs a fallback implementation if the method does not exist or if an error is thrown while calling it. This method is meant to determine if the pip toggle for a video should be hidden by the site wrapper.

Arguments:
  • video (HTMLVideoElement) – The originating video source element

Returns:

Boolean – Boolean value true if the pip toggle should be hidden by the site wrapper, or false if it should not

PictureInPictureChildVideoWrapper.timeFromSeconds(aSeconds)

Return hours, minutes, and seconds from seconds

Arguments:
  • aSeconds (Number) – The time in seconds

Returns:

String – Timestamp string

PictureInPictureChildVideoWrapper.updatePiPTextTracks(text)

Function to display the captions on the PiP window

Arguments:
  • text – The captions to be shown on the PiP window