Controls Plugin

mp4e:controls is the player's controls in three layouts: a bar for a mouse, a phone player's controls for wide video on a touch screen, and almost no chrome for tall video.

Overview

Controls (mp4e:controls, an official plugin) replaces the player's control strip with one that fits how the video is being watched. It picks its layout from the screen and the shape of the frame, so the same video feels right on a laptop, on a phone held sideways and on a phone held upright.

Controls is a family plugin: it has the family's six themes, its common style settings, and targets of at least 44 pixels on screen. It is a controls plugin, so it does not sit on a layer like an overlay: a video plays with it when the video's document chooses it. New Studio projects start with Controls, and the Studio's Player panel switches a project between the controls it has installed. A host can also put it on any video (below).

The three layouts

With layout: 'auto' the layout is chosen from the size and touch support the player reports to plugins (mp4e.getViewport()) and from whether a mouse or trackpad drives the screen, and follows the screen if it changes, for example when the phone is turned.

LayoutWhenWhat it looks like
barA mouse: no touch screen, or a touch screen driven by a mouse or trackpad (a touch laptop, a tablet with a trackpad)A strip along the bottom: play, mute with a volume slider, the time, settings and full screen, and a seek track with a gap where each chapter begins and a lighter band for the part of the video that has loaded. Pointing at the seek track, or dragging it, shows the time there and the name of its chapter. It hides after autoHideSeconds while the video plays, but not while the mouse is over it; moving the mouse over the video or pressing it brings it back.
touchA touch screen, frame as wide as it is tall or widerA tap shows a dark scrim with a big play/pause, skip back and forward buttons, mute and settings at the top right, and the time, full screen and a seek track (tap or drag) along the bottom. A double tap on the left or right third of the video skips. A tap on the scrim hides it. Settings open as a sheet from the bottom. While the controls are hidden and the video plays, the empty strip along the bottom takes no taps: a button, an object or a card there takes its own tap, and a tap on the bare video shows the controls.
immersiveA touch screen, frame taller than it is wideA thin progress line is always on screen. A tap shows the controls: buttons stacked in the corners and a play/pause in the centre. A tap never pauses the video by itself, because it may belong to something in the video. A double tap skips. While the controls are hidden and the video plays, the strip under the progress line takes no taps, so whatever is there in the video takes its own.
  • Paused, the overlays come first. In the touch and immersive layouts a paused video shows a compact bar along the bottom (play/pause, the seek line, the time and full screen) and nothing above it, so the video's overlays stay tappable. A tap on the video opens the full controls; while paused they fall back to the compact bar after autoHideSeconds. When something else pauses the video (an overlay, the host, the end of the video) the full controls step back to the compact bar at once, and a tap on the video that itself paused it (an object's card, an overlay) leaves the compact bar as it is, so the full controls never cover what that tap opened.
  • A double tap is two taps on the same side within 350 ms. A tap reveals the controls whatever pointer made it; a mouse moving over the video only brings back the bar.
  • A touch screen has no volume slider; Controls offers mute.
  • Full screen is reachable whenever the controls are on screen, at any player width.
  • Keyboard: with the seek track focused, Left and Right Arrow step 5 seconds and Home and End jump to the start and the end.

Videos viewers cannot seek

When a video's creator turns viewer seeking off (a branching show, a course that must be watched through; see Content Restrictions), the player refuses every seek a viewer asks for, and Controls leaves out what would not work: the seek track (with its time under the mouse, chapter marks and loaded band), the time, the skip buttons and double-tap skip, and on tall video the progress line. Play and pause, sound, settings and full screen stay, in every layout. A remote arriving from the side lands on play / pause. The player tells Controls itself; nothing needs setting.

Settings

Controls' own settings, plus the family's common style settings (theme, accent, size, ...):

PropTypeDefaultDescription
layout'auto' | 'bar' | 'touch' | 'immersive''auto'Automatic picks the layout from the screen and the shape of the frame (below). Pick one to force it.
autoHideSecondsnumber3How many seconds the controls stay up after a tap or a move while the video plays. 1 to 30.
skipSecondsnumber10How far a double tap or a skip button jumps, back or forward. 1 to 60.
showChaptersbooleantrueLeave a gap in the seek track where each chapter begins, and show the chapter's name when the mouse points at the track (bar layout).
fullscreenbooleantrueShow the full screen button. false hides it in every layout, for a page that already fills the screen, as on a TV.

Numbers may be numeric text; anything that is not a number falls back to the default and numbers are held to their range. Controls emits no events and has no actions.

Putting it on any video

A host does not need a video to carry Controls, or to be exported with them: add the plugin through overrides and tell the player to use it for its controls with pluginOverrides. The host's choice wins over whatever controls the file carries.

Swap in the Controls plugin
import { MP4EPlayer } from '@mp4e/react';

// The published Controls plugin, as the player's plugins entry
const row = await (await fetch('https://api.mp4e.com/api/plugins/slug/mp4e-controls')).json();
const controls = {
  id: `${row.namespace}:${row.identifier}`,
  name: row.name,
  type: row.type,
  category: row.category,
  version: row.version,
  content: row.content,
  configSchema: row.configSchema,
  defaultConfig: row.defaultConfig,
  sizing: row.sizing,
  source: 'marketplace',
  namespace: row.namespace,
  identifier: row.identifier,
  signature: { signer: row.signatureSigner, value: row.signatureValue },
};

<MP4EPlayer
  src="/video.mp4"
  overrides={{ plugins: { 'mp4e:controls': controls } }}
  pluginOverrides={{ controls: { pluginId: 'mp4e:controls' } }}
/>
Chosen when the player is created
pluginOverrides is read when the player is created. A host that decides later (the plugin's row arrives, or the viewer opts in) must remount the player, for example by changing its React key.

Without pluginOverrides, the player follows the video's document: player.controls.pluginId names the controls plugin, and player.controls.enabled: false shows no controls. A host can set that choice through overrides too, which takes effect without a remount:

Choose Controls through the document
<MP4EPlayer
  src={videoUrl}
  overrides={{
    plugins: { 'mp4e:controls': controls },   // the entry built above
    player: { controls: { enabled: true, pluginId: 'mp4e:controls' } },
  }}
/>

When the document makes no choice, or names a plugin it does not carry, the player uses the first plugin of the document whose type is controls, else its built-in controls.

If you write your own controls

Controls follows the same contract every controls plugin should follow, so a viewer gets the same behaviour whoever wrote the controls:

  • Reveal on the container tap, and never pause or play on it.
  • Swallow clicks your frame did not see pressed (below).
  • Keep full screen reachable whenever the controls are on screen.
  • Offer no volume slider when getViewport().hasTouch is true; mute only.
  • Make every target at least 44 pixels on screen.
  • Choose the layout from mp4e.getViewport() and follow mp4e.onViewportChange(), never from the user agent.
  • Mute with mp4e.setMuted(!mp4e.isMuted()).
  • When mp4e.getData().viewerSeeking is false, the video's creator turned viewer seeking off and the player refuses your seekToTime: hide the seek track, the time and skip, and keep play, sound, settings and full screen. Read it again on every mp4e:dataUpdate event, and treat a missing value as seeking allowed.

The container tap

When the viewer presses the video, or moves a mouse over it, the player posts a window message to the controls plugin:

PropTypeDefaultDescription
type'mp4e-container-tap'-Identifies the message.
x, ynumber-Where, from 0 to 1 of the video area (not counting letterbox bars), left to right and top to bottom. Use x to tell which side a double tap was on.
pointerType'touch' | 'mouse' | 'pen'-The input that made it.
kind'press' | 'move'-'press' for every pointer; 'move' for the mouse only, at most once every 250 ms.
Listening for the container tap
window.addEventListener('message', (e) => {
  if (e.source !== window.parent) return;   // only the player sends it
  const m = e.data;
  if (!m || m.type !== 'mp4e-container-tap') return;
  // m = { type, x, y, pointerType: 'touch' | 'mouse' | 'pen', kind: 'press' | 'move' }
  revealControls();      // show them and restart the hide timer
  // Do NOT play or pause here: the press may belong to an object or an overlay.
});

The tap is for revealing the controls and restarting the hide timer only. It never means play or pause, because the press may belong to an object in the video or to an overlay. Accept it only from the player's window (e.source === window.parent).

A press arrives after the player has handled the tap's click: the player notes the press when the finger goes down and posts it once the click has reached the objects and overlays under it. So controls that take the whole frame when they hear a press never catch that tap's click. A touch press that never becomes a click (the finger scrolled away) is not posted, and neither is a press whose click an overlay or a clickable region took for itself. A long press that stayed still is posted when the finger lifts: the browser sends no click for it. A keyboard click is never taken for a press.

Ghost clicks

A browser sends a tap's click after the finger lifts, to whatever is under it at that moment. Controls that appear or grow on a press can therefore receive a click that was not pressed on them, and a control that has just appeared under the finger would be pressed by accident. Guard against it before any other click listener:

Swallow clicks your frame did not see pressed
let pressed = false;
let releasedAt = 0;
let pressRevealed = false;   // set when a press only revealed the controls

document.addEventListener('pointerdown', () => { pressed = true; releasedAt = 0; }, true);
document.addEventListener('pointerup', () => { if (pressed) releasedAt = Date.now(); pressed = false; }, true);
document.addEventListener('click', (e) => {
  if (e.detail === 0) return;        // a keyboard click: always the viewer's
  // Timed from the release, so a slow press (held for seconds) still clicks.
  const pressedHere = releasedAt > 0 && Date.now() - releasedAt <= 400;
  releasedAt = 0;
  if (pressRevealed) {               // that press was the reveal, not a press on a button
    pressRevealed = false;
  } else if (pressedHere) {
    return;                          // a click this frame saw pressed and released
  }
  e.preventDefault();
  e.stopImmediatePropagation();
}, true);

Full frame only while shown

A controls plugin sits in a strip along the bottom of the video, drawn above every overlay, and the strip takes taps until the plugin says otherwise. A layout that draws over the whole video can ask for the whole frame while its controls are up, and give it back when they hide. When nothing the viewer can press is left in the strip, ask for pointerEvents: 'none', so the overlays and objects under it take their own taps; a tap on the bare video still reaches the plugin as mp4e-container-tap. Ask for 'auto' again as soon as something pressable is drawn there:

requestLayout while the controls are shown
// Show the controls over the whole video
mp4e.requestLayout({ position: 'fullscreen' });
mp4e.requestLayout({ pointerEvents: 'auto' });

// ...and when they hide, give the video back
closeSettingsMenu();                       // close the menu first
mp4e.requestLayout({ position: 'bottom' });
// Nothing pressable left in the strip: let taps through to the video
mp4e.requestLayout({ pointerEvents: 'none' });
  • Opening and closing the settings menu does not undo a full-frame request.
  • Close the menu before asking for bottom again: a bottom request made while the menu is open docks the strip at the menu's height.
  • While the controls cover the video, a tap on it hides them, so nothing under them is tappable meanwhile.

See Video Controls Plugins for the events and methods a controls plugin uses.