The element
@mattebox/player@0.18.0Needs @mattebox/player-core ^0.11.0 and mattebox ^0.21.0.
This chapter explains <mattebox-player>: its attributes, its properties
and its events. It then explains the controls placed inside it, which show
over the picture under controls="custom".
Attributes
| Attribute | What it does |
|---|---|
src |
Sets the source URL. A new value loads the new source. The same value again loads it again |
type |
Sets the MIME type of the source. Optional when the extension is known |
preset |
Names the engine preset. The default is full |
license-url |
Sets the DRM license URL. The player gives it to engine.drm.setLicenseUrl, or to attachEme for a native session |
certificate-url |
Sets the FairPlay application certificate URL. The player gives it to engine.drm.setCertificateUrl, or to attachEme for a native session. |
native-hls |
off keeps HLS on the engine in Safari, on plays it natively. Unset, Safari plays it, unless something needs the engine. Changes reload the source |
tooltips |
off hides the name each button shows over itself on hover and keyboard focus. The name is the button’s label, so a translated label translates it |
announce |
off silences the live region, for a page that announces changes itself. See Labels |
language |
Sets the locale of the labels. It overrides the nearest lang. See Localization. Changing it never reloads |
thumbnails |
Sets a thumbnail track URL. The player gives it to engine.thumbnails.load |
chapters |
Sets a chapters file URL. A session with engine.chapters loads it there. Any other session gets a hidden <track kind="chapters"> on the video. Changing it never reloads |
controls |
Selects the controls: native (the default), custom for the control elements inside the player, or none to hide every child but the video. Changing it never reloads |
subtitle-size |
Sets the subtitle size: small, medium, large or xlarge. The subtitles menu writes it. The default is medium |
subtitle-background |
Sets the subtitle background: none (transparent), dark (60% black) or solid (black). The default is dark |
layout |
The size tier the controls draw for: compact, regular or wide. The player sets it from its own size. A value you write stays. See Layout tiers |
drawer |
Opens a compact player’s menus and playlist in a drawer over the page. A control takes it too. See The drawer |
playsinline |
Plays inline on an iPhone. On by default. playsinline="false" lets the iPhone go to fullscreen on play. Changing it never reloads |
autoplay |
Copied onto the video as an attribute |
muted |
Copied onto the video, as an attribute and as the muted state. The player also writes the video’s muted state back to it |
poster |
Copied onto the video as an attribute |
crossorigin |
Copied onto the video as an attribute. A chapters track from another origin needs it |
disablepictureinpicture |
Copied onto the video as an attribute. The browser’s own picture-in-picture toggle, which Firefox draws over the video, goes away, and so does <mbx-pip-button> |
The player reports its state as attributes on itself, for the page’s
stylesheet and for the controls. mattebox-player[playing] matches while
the video plays.
| State attribute | Set by | While |
|---|---|---|
paused, playing, ended |
The player | The video is in that state |
muted |
The player | The video is muted |
audio |
The player | The source has no picture |
started |
The player | The video has played once since its source was set |
waiting |
The player | The video waits for data |
error |
The player | A fatal error stopped the load. Under custom controls, only the video, mbx-error-screen and mbx-diagnostics show |
blocked |
The player | A block shows. Under custom controls, only the video, mbx-error-screen and mbx-diagnostics show |
diagnostics |
@mattebox/player-diagnostics |
The diagnostics panel is open. The bar shows over an error or a block meanwhile |
live-captions |
@mattebox/player-live-captions |
Live captions are available: off or on. <mbx-live-captions-item> in the subtitles menu writes the value (chapter 15) |
subtitle-translation |
@mattebox/player-subtitle-translation |
The subtitles can be translated: off, or the language translated into. <mbx-subtitle-translation-items> in the subtitles menu offers the languages of subtitle-translation-languages for the track of subtitle-translation-source, and writes the value. subtitle-translation-progress is the download of that language (chapter 18) |
fullscreen |
The bar, the button | The player is the fullscreen element |
pip |
The picture-in-picture button | The video is in the floating window |
casting |
The player | A device plays in the video’s place. The value is its kind: chromecast or airplay |
airplay |
The AirPlay button | The video plays on an AirPlay target. Kept for one minor version: read casting |
idle |
The bar | The bar is hidden after a time without input |
focus-ring |
<mbx-gamepad> |
Every focused control shows its ring and its name, also after focus a script gave. Set it yourself when your own code moves focus for a remote |
live |
The seek bar | The stream has an availability window |
seekable |
The seek bar | The viewer can seek: VOD, or a live window that is wide enough |
scrubbing |
The seek bar | A pointer holds the seek bar and the video is paused for the drag. The value is the state before the drag, playing or paused, which the play buttons show |
projection |
The player | The source is 360°: equirectangular or half-equirectangular, from the source’s projection or the manifest (chapter 16) |
frame-packing |
The player | The frame holds a picture for each eye: top-bottom or side-by-side, from the source’s framePacking or the stream (chapter 16) |
switching |
The player | switchSource or a version loads, and the controls show the state from before it, playing or paused, until the new load has a frame |
audio comes from the type of the source until the metadata arrives: the
type attribute, or the URL’s extension. After that it comes from the size
of the video. Zero by zero means sound only. The attribute follows a stream
that moves to or from an audio-only rendition.
The player only reports audio. The box stays at 16:9 until the page
changes it, for example with
mattebox-player[audio] video { aspect-ratio: auto; height: 0; }.
Several sources
The player reads <source> children when it has no src attribute. It
tries them in their order, as a video does.
<mattebox-player controls="custom">
<source
src="vod/master.m3u8"
type="application/vnd.apple.mpegurl"
license-url="https://drm.example/fps"
certificate-url="https://drm.example/fps.cer"
/>
<source src="vod/manifest.mpd" type="application/dash+xml" license-url="https://drm.example/widevine" />
</mattebox-player>
Attribute of <source> |
What it does |
|---|---|
src |
Sets the URL of the source |
type |
Sets its MIME type. Optional when the extension is known |
license-url |
Sets the DRM license URL of this source. The player’s own is the default |
certificate-url |
Sets the FairPlay certificate URL of this source. The player’s own is the default |
- The
srcattribute wins over thesourcesproperty, and the property wins over the children. - A source the browser cannot play is replaced by the next one, until the video’s first
playingevent. - Each replaced source dispatches
errorwithfatal: falseand itssource. The last one is fatal. - The player does not read the
mediaattribute of a<source>. - The children are read when a load starts. A
<source>added while nothing is loaded starts a load.
Chapter 02 has the rules of the list.
Video versions
A source can declare other versions of its video, such as a sign-language
version, with <mbx-video-track> children. See
chapter 12.
Properties
| Property | What it is |
|---|---|
player |
The Player of the core |
sources |
The sources to try in order, set from script. Setting it loads. Null returns to the <source> children |
engine |
The engine of the current session, or null |
video |
The <video> inside, in light DOM |
error |
The fatal error of the current load. Null after a load starts and after playback resumes |
markers |
The ranges the page named in this source: see Markers |
chapters |
The programme’s chapters in order, each with start, end and title: the engine’s, else the video’s chapters track |
breaks |
Where the programme’s ad breaks are, which the seek bar draws as ticks. breaks.set(owner, list) sets one owner’s list |
spots |
The moments a package points at, such as the matches of a search in the transcript, which the seek bar draws as ticks. spots.set(owner, list) sets one owner’s list, each spot a time and an optional current |
interrupted |
True while interrupt() plays a source in the programme’s place |
blocked |
What block() set, or null: see Blocks |
programme |
What the current load resolved: see chapter 09 |
trackers |
The page’s trackers: see chapter 13 |
videoSources |
The video versions the source declares: see Video versions |
videoSource |
The version that plays, or null for the source itself |
projection |
How the picture maps onto a sphere, or null for a flat one: see chapter 16 |
framePacking |
How the frame holds a picture for each eye, or null for one picture: see chapter 16 |
language |
The language attribute, or empty. Setting it updates the labels at once |
locale |
The language tag of the locale in use: language, else the nearest lang. Empty without either |
selectVideoSource(version) plays a version of videoSources, or the
source itself for null. It fires videosourcechange, whose detail is the
version or null.
switchSource(source) loads another source of the same programme in
place, such as its DASH manifest in place of its HLS one. It works as a
version does: the same position, play state and tracks, with the frame and
the controls held. The markers stay. A new src, sources or <source>
load replaces it.
player.switchSource({ url: 'vod/manifest.mpd', type: 'application/dash+xml' });
interrupt(source) plays another source in the programme’s place, such
as an ad, on the same video, and resume() plays the programme again from
where it stopped, in the play state it had. No sourcechange fires: the
programme, its markers and its trackers stay. An error of the source is
not the programme’s, so the error screen stays away; listen to the video.
@mattebox/player-ads plays its MP4 ads this way.
await player.interrupt({ url: 'https://ads.example.com/ad.mp4', type: 'video/mp4' });
player.media.addEventListener('ended', () => player.resume(), { once: true });
message(id) returns the message of id in the player’s locale, or
undefined when the control’s built-in English applies.
MatteboxPlayerElement.addLocale(language, ...sources) registers a locale
for every player. See Localization.
retry() loads the sources again, in the order a load reads them: the
src attribute, the sources property, then the <source> children. On
a version of the picture, or after switchSource, it loads that source
again.
Events
The player dispatches the core’s sourcechange and error again as
CustomEvents on itself. They bubble and they are composed. detail is
the core’s payload. When sourcechange fires, engine already returns the
engine of the new session.
player.addEventListener('error', (event) => {
console.error(event.detail.code);
});
layoutchange fires when the size tier changes. Its detail is the new
tier.
localechange fires when the locale changes: a new language or lang, a
language that finished loading, or an addLocale call. Its detail is the
language tag, empty for English.
blockchange fires on block(), on unblock(), and when a new source
clears the block. Its detail is the block, or null.
programmechange fires when a load resolves its sources, before
sourcechange. Its detail is the programme, or null at an unload.
trackerschange fires when a tracker is added, removed, started or
stopped. Its detail is the list of trackers.
castload comes from the button of @mattebox/player-cast. It fires
before the request goes to the receiver. It bubbles, it is composed, and it
is cancelable. Its detail is the load request of the sender SDK. The page
sets customData on it for its receiver, or cancels the load. See
Casting.
seekkey comes from <mbx-control-bar> when a key would seek: the arrows,
or fast forward and rewind. It fires on the player before the seek, and it
is cancelable. detail.by is the seconds to move, seek-step or its
negative. A cancelled seekkey does not seek. The seek bar cancels it under
key-mode="preview" to aim instead. A page cancels it to seek its own way.
Markers
Markers are ranges you name from your content API: credits to skip, and parts that must not play. See chapter 11.
Blocks
block() shows why a programme does not play, in the player’s language,
and stops the load. See chapter 11.
define() options: stages, config, drm, connectors
With attributes only, the player uses the preset the preset attribute
names, and full by default. full has every stage the engine ships, so
every control has its namespace and the player plays every kind of source.
A smaller preset or a list of stages downloads fewer bytes, and loses the features of the stages left out. The engine’s guide, chapter 02, has the matrix.
From JavaScript, the constructor and the static define() take a handler
list or a stage list. The page then decides which stages the engine has.
import { MatteboxPlayerElement } from '@mattebox/player';
import hlsCmaf from 'mattebox/protocols/hls-cmaf';
import abr from 'mattebox/stages/abr';
MatteboxPlayerElement.define({ stages: [hlsCmaf(), abr()] });
define() also reaches a player that is already in the page’s markup, as
long as it has not loaded a source yet. A player keeps the stages of its
first load.
config tunes the kernel in the same way. It works with a preset from the
attribute and with a stage list. traceCapacity makes the engine keep its
trace for engine.error, and bufferGoalSeconds sets the buffer goal.
Every member of the engine’s KernelConfig is accepted. With a handler
list, the config goes on the handler.
MatteboxPlayerElement.define({ config: { traceCapacity: 500 } });
drm sets the DRM of a native session. It takes the options of
attachEme from mattebox/eme. See Native HLS in Safari.
connectors registers one connector per source type, which turns a
programme id into what plays. A player keeps the connectors of its first
load. See chapter 09.
Native HLS in Safari
Safari plays an HLS source natively, through video.src. The engine does
not run. FairPlay, AirPlay, Low-Latency HLS and the iPhone’s fullscreen are
then Safari’s own.
The player prefers native HLS when all of these hold:
- The source is HLS.
navigator.vendorstarts withApple. Every browser on WebKit reports it.video.canPlayType('application/vnd.apple.mpegurl')is not empty.
Android Chrome also answers canPlayType for HLS. The vendor check keeps it
on the engine. DASH stays on the engine in every browser.
native-hls="off" keeps HLS on the engine. So does an add-on that sets
engine, such as ads(): Safari’s own HLS plays interstitials itself and
reports nothing a page can read. So does an element inside the player whose
needsEngine is true, such as <mbx-360>: over Safari’s own HLS its video
shows flat. native-hls="on" prefers Safari’s own HLS again, over an
add-on and an element. A page with its own handlers decides the order
itself.
A native session has no engine, so player.engine is null. The controls
read the video instead:
| Control | In a native session |
|---|---|
mbx-audio-menu |
Lists video.audioTracks. A choice sets enabled |
mbx-video-menu |
Lists video.videoTracks. A choice sets selected |
mbx-subtitles-menu |
Lists the subtitles and captions tracks of video.textTracks. A choice sets mode |
mbx-drm-badge |
Reads session.eme.drm when the session attached DRM |
mbx-chapters-menu |
Reads the chapters track of the video, as for any session |
mbx-quality-menu |
Hidden. Safari picks the rendition |
mbx-scan-button |
Hidden |
| Thumbnails and previews | None |
A menu hides when the browser has no such list. Forced subtitles show by
Safari’s own choice. A captions track carries the SDH badge. An audio
track of kind description carries the AD badge.
Errors are the video’s MediaError codes, plus the DRM errors of the
attachment.
DRM in a native session
The player attaches the engine’s DRM to the video before it sets src, with
attachEme from mattebox/eme. It detaches it when the session ends.
- The key systems are the
eme-fairplayandeme-cencstages of the engine’s stack: the preset’s, or thestagesoption’s. license-urlsets the license URL, andcertificate-urlthe FairPlay certificate.- The
drmoption adds to them:keySystems,licenseUrl,licenseUrls,requestHook. - The engine’s request hooks do not apply.
requestHookrewrites the license and certificate requests. - A browser without EME attaches no DRM, as for the engine.
FairPlay needs the application certificate:
import { MatteboxPlayerElement } from '@mattebox/player';
import emeFairplay from 'mattebox/stages/eme-fairplay';
MatteboxPlayerElement.define({
drm: {
keySystems: [emeFairplay({ certificateUrl: 'https://drm.example/fps.cer' })],
licenseUrl: 'https://drm.example/fps',
requestHook: (request) => {
request.headers.Authorization = `Bearer ${token}`;
},
},
});
Custom controls

controls="custom" removes the browser’s controls from the video. The
controls are then elements placed inside the player, next to the video.
The bar shows its children in their order. A control left out does not appear. Each control takes its parameters and its labels as attributes, and its icon through a slot.
<mattebox-player src="…" controls="custom">
<mbx-title></mbx-title>
<mbx-start-button></mbx-start-button>
<mbx-marker-button></mbx-marker-button>
<mbx-error-screen></mbx-error-screen>
<mbx-spinner></mbx-spinner>
<mbx-control-bar>
<mbx-current-time></mbx-current-time>
<mbx-seek-bar></mbx-seek-bar>
<mbx-duration></mbx-duration>
<mbx-play-button label-play="Reproduir" label-pause="Pausa"></mbx-play-button>
<mbx-skip-button seconds="15"></mbx-skip-button>
<mbx-spacer></mbx-spacer>
<mbx-fullscreen-button>
<svg slot="icon-enter" viewBox="0 0 32 32">…</svg>
</mbx-fullscreen-button>
</mbx-control-bar>
</mattebox-player>
Under custom the player adds no control of its own. A player with no
control elements shows only the video. A starting markup with most of the
controls:
<mbx-title></mbx-title>
<mbx-start-button></mbx-start-button>
<mbx-error-screen></mbx-error-screen>
<mbx-spinner></mbx-spinner>
<mbx-control-bar>
<mbx-current-time></mbx-current-time>
<mbx-seek-bar></mbx-seek-bar>
<mbx-duration></mbx-duration>
<mbx-live-button></mbx-live-button>
<mbx-skip-button seconds="-10"></mbx-skip-button>
<mbx-play-button></mbx-play-button>
<mbx-skip-button seconds="10"></mbx-skip-button>
<mbx-volume></mbx-volume>
<mbx-spacer></mbx-spacer>
<mbx-speed-menu></mbx-speed-menu>
<mbx-chapters-menu></mbx-chapters-menu>
<mbx-subtitles-menu></mbx-subtitles-menu>
<mbx-audio-menu></mbx-audio-menu>
<mbx-quality-menu></mbx-quality-menu>
<mbx-airplay-button></mbx-airplay-button>
<mbx-pip-button></mbx-pip-button>
<mbx-fullscreen-button></mbx-fullscreen-button>
</mbx-control-bar>
The bar has two rows: the seek row above the buttons row.
- A child with
slot="seek"goes in the seek row. - The times, the seek bar and the live button go in the seek row by themselves, unless the page wrote a
sloton them. - Every other child goes in the buttons row, in its order.
<mbx-spacer>pushes the controls after it to the right.
Per-control imports
The root entry registers every element, and the CDN bundle contains them all. A page on a bundler imports the player alone and one entry per control it places. The bundle then contains only those controls.
import '@mattebox/player/element';
import '@mattebox/player/elements/control-bar';
import '@mattebox/player/elements/play-button';
import '@mattebox/player/elements/seek-bar';
Each control entry registers its element and the player.
An element the page did not import renders nothing.
Control elements
Each element reads and writes the video from outside, as a page would. It reads the engine’s namespaces through the player.
An element that reads a namespace hides while the session has none. A native session shows no quality menu and no live button. Its audio and subtitles menus read the video’s own track lists. See Native HLS in Safari.
| Element | Attributes | Labels | Icon slots | What it does |
|---|---|---|---|---|
mbx-control-bar |
idle-ms, seek-step, tap-plays |
Lays out the controls over the picture. It fades, handles the shortcuts, the click and the tap on the video, and moves the subtitles above itself | ||
mbx-spacer |
Takes the free room in a row | |||
mbx-play-button |
label-play, label-pause, label-replay |
icon-play, icon-pause, icon-replay |
Plays and pauses. Replays after the end | |
mbx-mute-button |
label-mute, label-unmute |
icon-mute, icon-low, icon-high |
Mutes and unmutes. The icon shows the level. Sets aria-pressed |
|
mbx-volume-slider |
step, page |
label |
Sets the volume. It shows zero while muted, and a level above zero unmutes. Has dragging during a drag |
|
mbx-volume |
Groups the mute button with a slider that unfolds under the pointer or on focus. It fills itself with both when left empty | |||
mbx-skip-button |
seconds, negative for back |
label with {seconds} |
icon |
Moves the playhead by seconds, within the range the video can seek |
mbx-scan-button |
direction, forward or backward; rates, space-separated, each above 2 |
label |
icon |
Scans through the I-frame track with engine.trick.setRate. Each press steps up through rates, and a press past the last plays at normal speed. Hidden without an I-frame track. Has scanning and aria-pressed while it scans |
mbx-current-time |
Shows the position, such as “1:23”. On live, it shows the wall clock or the distance behind the edge. Hidden on a live stream that is not seekable | |||
mbx-duration |
Shows the duration, such as “4:56”. Hidden on live | |||
mbx-remaining-time |
Shows the time left, such as “-4:53”. Hidden on live. The one for a bar that shows a single number | |||
mbx-seek-bar |
step, page, live-window, chapters, scrub, preview, key-mode |
label, label-of with {current} and {duration}, label-behind with {time}, label-blocked |
Shows the position, the buffered ranges, the live window and its edge, and the preview. It is divided at the chapters, and the preview names the chapter. chapters takes divided, titles, both (the default), or none. A drag scrubs through the I-frame track when there is one. scrub="false" turns that off. preview orders the preview’s picture sources, frames tiles by default. key-mode="preview" makes the keys aim a target instead of seeking. Sets live, seekable and scrubbing on the player. Has dragging during a drag |
|
mbx-live-button |
text, label-live, label-at-edge |
Shows on a live stream and seeks to the edge. Disabled at the edge, where it has at-edge |
||
mbx-speed-menu |
rates, space-separated |
label, label-normal, label-back with {page} |
icon |
Sets video.playbackRate. Works for every session. Hidden during a cast |
mbx-chapters-menu |
label, label-back |
icon |
Lists the chapters with their start times, and checks the current one. Each item shows the chapter’s picture when every chapter has one. A choice seeks. Hidden without chapters. Works for every session | |
mbx-quality-menu |
label, label-auto, label-back |
icon |
Pins a rendition through engine.quality. Auto means no pin |
|
mbx-audio-menu |
label, label-back, label-ad, label-original, label-track |
icon |
Selects the audio track through engine.tracks, or video.audioTracks in a native session. Lists only tracks the engine can play. Shown when there is more than one. Marks an audio description track and the original language with a badge |
|
mbx-video-menu |
label, label-back, label-track, label-main, label-alternative, label-sign, label-captions, label-subtitles, label-commentary |
icon |
Selects the version of the picture: a video track through engine.tracks, or video.videoTracks in a native session, or a version at its own URL through selectVideoSource. One entry per version: the same picture in another codec is one entry. Not the quality menu: each version has its own bitrates. Shown when there is more than one |
|
mbx-subtitles-menu |
label, label-back, label-off, label-track, label-settings, label-size, label-background, label-small, label-medium, label-large, label-xlarge, label-none, label-dark, label-solid, label-sdh, label-cc |
icon, icon-on |
Selects the text track, or off, through engine.tracks, or video.textTracks in a native session. Draws what its children add: live captions after Off (chapter 15), the translation of the track that shows, after the tracks (chapter 18), or items you add. Lists only tracks the engine can play, in-band captions included. Forced tracks are not listed, and the menu reads off while one shows. Marks SDH subtitles with a badge. Its Settings page sets the size and the background, and writes subtitle-size and subtitle-background on the player |
|
mbx-drm-badge |
label with {system} and {keys}, label-key and label-keys with {count} and {statuses}, label-no-key |
icon |
Shows a lock for engine.drm, or session.eme.drm in a native session, with a tooltip on hover and on focus |
|
mbx-airplay-button |
label, label-active |
icon, icon-active |
Opens Safari’s AirPlay picker. Hidden without AirPlay and while the video offers no target. Sets airplay on the player |
|
mbx-pip-button |
label-enter, label-exit |
icon-enter, icon-exit |
Toggles picture in picture. Hidden without the API. Sets pip on the player |
|
mbx-fullscreen-button |
label-enter, label-exit |
icon-enter, icon-exit |
Toggles fullscreen on the player. Hidden without the API. Sets fullscreen on the player |
|
mbx-start-button |
label-play, label-replay |
icon-play, icon-replay |
Shows a large play button over the picture while paused, and a replay after the end. Hidden while playing, behind an error, and in a box too short to keep it above the bar. A seek keeps the state from before it | |
mbx-marker-button |
label-opening-credits, label-closing-credits, label-skip |
Shows a skip button over the picture inside a marker the page set, other than blocked. A press moves to the marker’s end. It sits above the bar, stays there when the bar hides, and hides once the media has ended. While the player carries upnext, a card such as the playlist’s <mbx-up-next> covers the closing credits, and the button leaves them to it |
||
mbx-error-screen |
label-title, label-retry, label-blocked, label-diagnostics |
Shows a fatal error over the picture, with the category, the code and a retry that calls the player’s retry(). With mbx-diagnostics in the player, a second button opens its panel. Shows the page’s block, with its title and message and no retry |
||
mbx-spinner |
label |
icon |
Shows a turning ring in the place of the start button while the video plays and the player has waiting. A wait while paused, such as a seek, keeps the start button |
|
mbx-title |
heading, subheading, artwork |
Shows the artwork next to the heading and subheading, above the bar. Beside artwork, a long heading wraps to three lines, or two above a subheading; without artwork it keeps one line. Shown while the video is paused, including before the first play. A seek while playing does not show it. Has playing for the page’s own rule |
The title’s content comes from its attributes, because the stream has none of it. It goes first among the screens, so its band paints under the start button and the spinner.
CSS decides when the title shows. By default it shows while the video is paused, which includes the time before the first play.
mattebox-player[started] mbx-title { display: none }shows it only before the first play, like the poster.mattebox-player:hover mbx-title { display: flex }shows it again on hover.
Every menu has open on itself while its popup shows. The bar does not
fade while an element inside it has open.
A popup never leaves the picture. It uses the room above its button as its height, and scrolls when it needs more.
Casting
While a device plays in the video’s place, the player keeps its own controls. They drive the device: play, pause, the seek bar, the volume, the chapters and the skip buttons. The video on the page stays paused. The bar does not hide during the cast, and a tap on the picture plays or pauses.
- The player has
castingwith the kind of the device:chromecastorairplay. It firescastingchange, andplayer.castingreads the kind and the name of the device, or null. <mbx-casting>covers the picture with the programme’s poster, dimmed, and shows the device’s glyph over a line that names it: “Casting to Living room”. Under AirPlay the line is “Playing on AirPlay”, since Safari does not name the target. Place it before the other screens.- The quality menu, the video menu, the scan buttons, fullscreen and picture in picture hide during a cast. The device picks its own quality.
- The speed menu hides during any cast: a Chromecast plays its own engine, and an AirPlay target ignores the video’s rate.
- The audio and subtitles menus hide during a Chromecast session. They stay under AirPlay.
- A drag on the seek bar shows the preview and seeks once, on the release.
- A load during the cast goes to the device, such as the next item of a playlist.
A hidden control carries away.
AirPlay needs nothing more than its button: Safari plays the video on the
device. Chromecast is @mattebox/player-cast, a package of its own. Its
button loads Google’s sender SDK onto the page, and the player never loads
third-party code for a page.
<mattebox-player src="…" controls="custom">
<mbx-casting></mbx-casting>
<mbx-control-bar>
…
<mbx-airplay-button></mbx-airplay-button>
<mbx-cast-button></mbx-cast-button>
</mbx-control-bar>
</mattebox-player>
<script type="module">
import '@mattebox/player';
import '@mattebox/player-cast';
</script>
<mbx-cast-button> starts and ends a Chromecast session.
The button loads the SDK from gstatic the first time it connects. It does
not load the SDK when the page already has it, or when the button has
sdk="none". In that case the page loads the SDK.
receiver is the id of the receiver application. Without it, the button
uses the Default Media Receiver. The first button on the page decides the
receiver, because the SDK keeps one context per page.
| Element | Attributes | Labels | Icon slots |
|---|---|---|---|
mbx-cast-button |
receiver, sdk |
label-start, label-stop |
icon, icon-active |
mbx-casting |
label with {device}, label-airplay |
When a session starts, the player does this:
- It pauses the video.
- It suspends the engine, so the engine requests nothing during the cast. The source stays loaded, so the chapters, the markers and the thumbnails keep working.
- It sends the source of the session at the video’s current time, and
LIVEfor a live stream. A live viewer behind the edge continues at the same moment, when the stream carries a clock. - It sends the programme with the source: the title, the image, the chapters, the markers, the subtitle files of the video, the thumbnail track, and the connector’s type and id.
- It sets
casting="chromecast"on itself.
When the session ends, the engine resumes. The video seeks to the time where the receiver stopped, and plays if the receiver was playing. A live stream returns to the live edge instead.
The Default Media Receiver plays clear HLS and DASH and shows the title.
It reads nothing else: no marker, no chapter and no DRM server. A receiver
built on @mattebox/cast-receiver reads them all, in
customData.mattebox. A receiver page with the same connector loads the
programme by its type and id, with its own token.
License headers and other secrets are the page’s to add, in castload:
player.addEventListener('castload', (event) => {
event.detail.customData.mattebox.licenseHeaders = { Authorization: `Bearer ${token}` };
});
player.media is what the controls read and call. It behaves as the
<video>, and during a cast its playback members are the device’s. It is
not a DOM node. For an API that takes the element itself, such as an
observer, read the <video> child of the player.
Seek through player.media, not through the <video>. Apple’s WebKit
loses a seek made before the first frame of a source it plays itself, as
on an iPhone before the viewer plays, and no later seek works.
player.media keeps such a seek and makes it at the first frame, and its
currentTime reads the time kept until then.
Chapter 02 has the detail.
Localization
The controls ship their labels in English and in 11 other languages. A
player takes its locale from its language attribute, or from the nearest
lang. Chapter 10 explains how you register a locale
and how the player picks one.
Labels
Every text a control shows, and every accessible name it has, is a
label attribute of that control. The attribute overrides the player’s
locale. Each state has its own attribute: label-play, label-pause,
label-replay.
A label can contain a value in braces: label="Enrere {seconds} segons". A
name in braces the control does not know stays as written.
<mbx-play-button label-play="Reproduir" label-pause="Pausa" label-replay="Torna a reproduir"></mbx-play-button>
<mbx-skip-button seconds="-10" label="Enrere {seconds} segons"></mbx-skip-button>
<mbx-seek-bar label="Cerca" label-of="{current} de {duration}"></mbx-seek-bar>
Track names
The audio and subtitles menus name a track by the first of these it has:
- The name in the manifest (HLS
NAME, DASHLabel), or the label of a native track. - The language’s name in the player’s locale (see
Localization), else the page’s (
langon<html>), else the browser’s. This needsIntl.DisplayNames, which Chromium 76 and 79 do not have. - The language code.
- “Track” (
label-track) and the track’s place in the list.
The role main is not shown. Two tracks that read the same take a hint in
parentheses: the audio channel layout (“Stereo”, “5.1”) when the engine
gives one, then the role, then the place in the list. “Mono” and “Stereo”
come from label-mono and label-stereo on the audio menu.
Track badges
A badge after the name marks a standard characteristic, from the engine’s track functions.
| Badge | Attribute | Menu | Track |
|---|---|---|---|
AD |
label-ad |
audio | Audio description |
Original |
label-original |
audio | The original language |
SDH |
label-sdh |
subtitles | Subtitles for the deaf and hard of hearing |
CC |
label-cc |
subtitles | Closed captions carried in the video |
The player draws AD, SDH and CC as a glyph. The label is the glyph’s
tooltip, and the text a screen reader says.
Live region announcements
The player has an ARIA live region for screen readers. It announces a play, a pause, a wait of over a second, a fatal error and a track change.
- It announces a track change only after the first play.
- It announces no error while an
mbx-error-screenis inside the player, because the screen is an alert itself. - Each announcement is a
labelattribute of the player, which overrides its locale. announce="off"on the player turns the live region off.
| Attribute | English | Said when |
|---|---|---|
label-playing |
Playing |
The video plays |
label-paused |
Paused |
The video pauses, except at its end |
label-loading |
Loading |
The video has waited for data for 1 s |
label-error |
Playback failed |
A fatal error ends the load |
label-audio |
Audio: {track} |
Another audio track plays |
label-subtitles |
Subtitles: {track} |
Another subtitle track shows |
label-subtitles-off |
Subtitles off |
No subtitle shows. A forced one reads off |
{track} is the track’s name in the stream, else its language’s name.
Quality names
The quality menu lists engine.quality.selectable, best first: what the
browser can play, one entry per video stream. A name grows only as far as
it must to tell entries apart.
- The height, such as
1080p, or the bitrate without one. - The frame rate above 30, such as
1080p60. Dolby VisionorHDR, such as1080p HDR.- The bitrate, when two entries still read the same:
1080p60 · 6.2 Mbps. - The codec, when they still do:
1080p · 6.1 Mbps · HEVC.
Entries that read the same after that, such as one stream on two CDNs, show once.
Under Auto, the Auto row names what plays in its detail, such as Auto 720p. These names come from the stream and have no attribute.
Icons
Every button has one named slot per state for its icon. The button shows its own icon when the slot is empty.
A page puts its own SVG in the slot. The button keeps its name: the icon is
decoration with aria-hidden, and the name is on the button, where a
screen reader reads it.
<mbx-play-button>
<svg slot="icon-play" viewBox="0 0 24 24"><path d="…" /></svg>
<svg slot="icon-pause" viewBox="0 0 24 24"><path d="…" /></svg>
</mbx-play-button>
The player’s own icons are Mattebox’s drawings: one filled path each, on a 32-unit grid, so they scale to any size and take the text colour.
Write your own control
Any element inside the bar is a control. It shows in the row where the page put it. It finds its player the way the player’s own controls do:
- The nearest
mattebox-playerabove it, through shadow hosts. Wait forcustomElements.whenDefined('mattebox-player')before reading it. player.mediafor playback,player.enginefor the namespaces (null for a native session),player.playerfor the core, andplayer.error.sourcechangeon the player for a new session,errorfor a failure.openon itself while it shows a popup, so the bar does not fade.- A real
<button>for anything Space must activate. The bar leaves Space to a focused button.
The player’s own controls use only this API.
@mattebox/player-diagnostics and @mattebox/player-cast are controls
written this way, in packages of their own. Chapter 05 covers the
diagnostics, and Casting covers the cast.
Add items to a menu: menuAddition()
A menu renders the items its child elements return. Put an element inside
<mbx-subtitles-menu>, or inside any other menu, and give it a
menuAddition() method. The menu renders the items like its own: the same
keys, the same check mark, the same part names.
<mbx-subtitles-menu>
<my-sign-language></my-sign-language>
</mbx-subtitles-menu>
import type { MenuAddition } from '@mattebox/player';
class MySignLanguage extends HTMLElement {
on = false;
menuAddition(): MenuAddition | null {
return {
items: [{ value: 'sign', label: 'Sign language' }],
value: this.on ? 'sign' : null,
onSelect: () => this.set(true),
active: this.on,
clear: () => this.set(false),
};
}
set(on: boolean): void {
this.on = on;
this.dispatchEvent(new Event('menuchange', { bubbles: true }));
}
}
customElements.define('my-sign-language', MySignLanguage);
| What the child returns | What the menu does with it |
|---|---|
items |
Draws them in its main list. The subtitles menu puts them after Off, the other menus at the end |
value, onSelect |
Checks the item with that value, and calls onSelect with the value of the item chosen |
entries |
Draws lists after the main list, each with a heading, and links that open a page of lists |
active |
While true, checks none of its own items. The subtitles menu shows its glyph as on. A child that changes how the menu’s own choice reads, as a translation does, returns false |
clear |
Calls it when the viewer chooses the menu’s own item, or another child’s |
null |
Draws nothing for this child |
- One choice is checked across the menu’s own items and every child’s.
- Choosing a child’s item in the main list of the subtitles menu clears the other children, then turns the selected track off. Choosing in a child’s list leaves the track alone.
- Dispatch
menuchange, bubbling, when the answer changes. The menu stops the event and draws again. It also draws again when a child comes or goes. - An item takes
detail, drawn at its end,image, andbadges. A badge with aglyphshows the glyph, and itslabelis read by a screen reader. - A list’s
namestarts its part names:name: 'dubbed'givesdubbed-section,dubbed-labelanddubbed-item. - The child is not drawn itself. The types are
MenuAddition,MenuItem,MenuList,MenuLink,MenuBadgeandMenuChild.
@mattebox/player-live-captions and
@mattebox/player-subtitle-translation add to the subtitles menu this way.
The menu imports neither package.
The control bar
Auto-hide
The bar fades on one timer. Any pointer movement or press, any key, and the
start of playback restart the timer for idle-ms. When the timer ends, the
bar hides, except in four cases:
- The video is paused.
- A device plays in the video’s place. See Casting.
- An element inside the bar has
open. - Keyboard focus is inside the bar.
The bar never tracks whether the pointer is over it. The fade respects
prefers-reduced-motion.
Responsive collapse: the priority attribute
A narrow bar hides controls from its buttons row instead of overflowing.
Each child has a priority, and the bar hides the highest number first:
| Priority | Controls |
|---|---|
| 6 | The scan buttons |
| 5 | The volume slider |
| 4 | The diagnostics, the DRM lock, the speed and chapters menus |
| 3 | The audio and quality menus, picture in picture |
| 2 | The skips |
| 1 | The subtitles and video menus, the mute button and the volume group |
| 0 | Everything else. Never hidden: play and fullscreen stay at every width |
A priority attribute on a control replaces its default. A page’s own
control in the bar starts at 0.
While the buttons need more room than the row has, minus a few pixels of
tolerance, the bar sets collapsed on the highest numbers, one at a time.
Among equal numbers it starts from the right. It removes the attribute
again when the bar gets wider.
The bar counts the folded volume slider at its unfolded width, so the row has room for the slider when it unfolds. The slider is the first control to go.
collapsed is an attribute, and one rule of the bar hides a collapsed
control. mbx-speed-menu[collapsed] is therefore the page’s to style. A
page with its own breakpoints sets every priority to 0 and writes container
queries on the player.
Fullscreen
Fullscreen goes on the player itself. Every control placed inside stays
visible, and mattebox-player:fullscreen matches. The player also sets
fullscreen on itself, for the Safari versions that only have the prefixed
API. mattebox-player[fullscreen] > video is where a page lifts a height
limit it set on the video.
Subtitle position and style
The subtitles are the browser’s own cues on the video. The bar moves the active cues above itself while it shows. When it hides, they rest one line above the picture’s bottom edge. It only moves a cue the author did not position. Two cues that show at once stack, each by its measured height.
The bar styles the cues with a small stylesheet it adds to the document
once, with one rule per size and one per background. The stylesheet must be
in the document: ::cue only accepts rules from the document that holds
the video, and it accepts no custom properties.
The sizes are percentages of the browser’s own cue size, which follows the
height of the video. A page that wants more writes its own
mattebox-player > video::cue rule. That rule wins because it comes later.
In Chrome on macOS, subtitle-background changes nothing. Chrome there
takes the background of a cue from the caption style of macOS, and that
background wins over the ::cue rule of a page. It reads the style from
System Settings, under Accessibility, Captions
(caption_style_mac.mm).
subtitle-size works there, and Chrome on Windows applies both attributes.
Live streams
On a live stream, the seek bar shows the availability window and marks the edge. The live button seeks to the edge on a click. The time and the hover preview show the wall clock when the stream has an anchor (a program date time or an availability start). Otherwise they show the distance behind the edge.
A window shorter than live-window buffer goals gets no seek bar, because
the viewer has no range to seek in. The live button then stays red and
disabled.
Keyboard shortcuts
Every control is reachable with the keyboard, and every control has a name. The sliders announce their value in words. While focus is inside the player, these keys work from every control:
| Key | What it does |
|---|---|
Space, k |
Plays or pauses. Space on a focused button activates that button |
m |
Mutes or unmutes |
f |
Enters or leaves fullscreen |
| Left, Right | Seeks by the seek-step of the bar |
| Play/Pause, Play, Pause | The media keys a remote or a keyboard sends: play or pause |
| Stop | Pauses. The source stays |
| Fast Forward, Rewind | Seek by the seek-step of the bar |
| Up, Down, Page keys, Home, End | On a slider, moves it by its step, by its page, or to its end |
| Up, Down, Home, End, Escape | In a menu, moves the selection. Escape goes back a page, then closes the menu |
Click and tap on the video
A click on the video plays or pauses. A tap does not: on a touch screen, a
tap on the picture shows the bar while it is hidden and hides it while it
shows, as on a phone’s own players. The player tells a tap from a click by
the pointer’s type, not by the device, so a laptop with a touch screen
gets both. tap-plays on the bar gives a tap the click’s play and pause
back. During a cast a tap plays and pauses, since the bar stays.
Menus and panels
A menu stays open after a choice, on the page the choice was made on, and the check moves. It closes on Escape, on a press on its button, or on a press anywhere else.
While a menu or a panel is open, a click on the video closes it and does
nothing else: it does not play or pause. A panel is a child of the player
that carries open, as <mbx-transcript> and <mbx-playlist> do. The bar
removes the attribute. Give a panel of your own the same attribute and it
closes the same way.
Focus and key handling
Under custom the player sets
tabindex="0" on itself, so the shortcuts still work after a click on the
video. A page that set its own tabindex keeps it.
A key another handler already prevented is left alone. A handler that listens on the player in the capture phase runs first, and takes a key by preventing it.
Native controls
Under controls="native", the video shows the browser’s own controls and
the player appends nothing. The quality, the tracks and the rest have no
control, because the browser’s controls do not show them. A page that
wants them uses controls="custom".
Under native controls, a fatal error shows in the player’s own row under
the video, the error surface, with the category, the code and a retry.
Under custom, <mbx-error-screen> shows the error instead. A block
shows in the same places, with its title and message and no retry.
controls="none" takes the browser’s controls off the video, appends
nothing, and hides every child but the video. A page keeps its composition
in place and turns it off with the one attribute. The bar’s shortcuts still
listen while hidden, and the error surface still shows a fatal error.
The live button needs more than its namespace. full has both live stages,
so engine.live exists for a VOD stream too. A stream is live when it has
an availability window, so the button shows only after edge is set.
Thumbnails
Native controls do not report the scrub position, so thumbnails have no preview there.
- Under
controls="native", thethumbnailsattribute loads the track and the player draws nothing. The app callsengine.thumbnails.at(time). - Under
controls="custom", the preview of the seek bar shows a picture above the pointer, scaled to--mbx-preview-width, 160px by default.
Seek keys: the key-mode attribute
On a TV, a seek per key press stutters. key-mode="preview" on the seek
bar makes the keys aim instead:
- The arrows, Page Up, Page Down, Home, End, fast forward and rewind move a target. The thumb and the preview show it, and the video keeps playing.
- A held key’s step grows, so a long film takes seconds to cross.
- Enter seeks to the target. So does moving focus off the bar, or a second without a key.
- Escape, Back, or a click outside the seek bar drops the target.
The default, key-mode="instant", seeks on every key.
Seek preview pictures: the preview attribute
The preview’s picture comes from the sources in the seek bar’s preview
attribute, in order of preference. The first one that answers for
the time wins. Without a picture, the preview shows the time and the
chapter.
preview |
Picture |
|---|---|
frames tiles (default) |
The decoded I-frame; the tile until it arrives, or without one |
tiles frames |
The tile; the decoded I-frame where the stream has no tile |
tiles |
The tile only |
frames |
The decoded I-frame only |
none |
No picture |
A decoded I-frame comes from engine.trick.frameAt. It needs an I-frame
track, WebCodecs, and clear fMP4. A tile comes from engine.thumbnails.
Trick play: scrub and scan
A drag on the seek bar scrubs when the session has an I-frame track. The
video pauses and shows the I-frame at each position, and the release seeks
there. scrub="false" on the seek bar turns this off. Without scrubbing,
the video pauses and seeks as the pointer moves, and
the release resumes playback if it was playing. Thumbnail tiles never drive a drag:
they are previews, not frames of the video.
<mbx-scan-button> shows only with an I-frame track. Place one of each
direction around the play button:
<mbx-scan-button direction="backward"></mbx-scan-button>
<mbx-play-button></mbx-play-button>
<mbx-scan-button></mbx-scan-button>
Chapters
Chapters come from the engine when the session holds some, and from a text
track of kind chapters on the video otherwise. There are four ways to add
them:
- The
chaptersattribute with a URL. A session withengine.chaptersloads it there, in every format the engine reads. Any other session gets a hidden<track>. - The manifest. The engine reads the chapters an HLS playlist names.
engine.chapters.set(list)with chapters the page already holds, such as ones from a content API.- A
<track>on the video written by the page, or a track built withaddTextTrack.
The seek bar leaves a gap at each chapter boundary and names the chapter in
the preview. <mbx-chapters-menu> lists the chapters, with their pictures
when every chapter has one. Chapters work for a native session too, from a
text track.
<mattebox-player src="https://example.com/vod/master.m3u8" chapters="/vod/chapters.vtt" controls="custom"></mattebox-player>
Styling
The controls are elements in the page’s own light DOM. The page’s
stylesheet selects each one by its tag: mbx-play-button { margin: 0 4px }.
The inside of a control is in shadow DOM. ::part() reaches it, and
accepts every CSS property. The state is an attribute on the element, so a
selector can read it.
mbx-play-button::part(button) { border-radius: 50%; }
mattebox-player[playing] mbx-play-button::part(icon) { fill: rebeccapurple; }
mbx-quality-menu::part(item):hover { background: rebeccapurple; }
mbx-live-button[at-edge]::part(dot) { box-shadow: none; }
mbx-control-bar { background: #000; }
Two rules make this work:
- No stylesheet of the player uses
!important. For normal declarations, a rule from the page wins over a rule from the shadow tree, whatever its specificity. An!importantinside the shadow tree would reverse that. - Every element a control draws has a
part, because::part()cannot select the descendants of a part.
| Element | Parts |
|---|---|
mattebox-player |
stage, and the error surface: error, error-category, error-code, error-retry, value, button |
mbx-control-bar |
row, seek-row, buttons-row |
| Every button control | button, icon |
mbx-volume-slider, mbx-seek-bar |
slider, rail, track, fill, thumb |
mbx-seek-bar |
buffered, buffered-range, blocked, blocked-range, hover, edge, preview, preview-frame, preview-image, preview-tile, preview-title, preview-time, spots, spot |
mbx-scan-button |
button, icon, rate |
mbx-live-button |
button, dot, text |
| Every menu | button, icon, popup, drawer, title, section, section-label, item, item-image, item-badge, item-glyph, badge-text, item-detail, page-item, glyph-item, back-item, and <name>-item and <name>-section per group |
| The chosen item of a menu | checked, added to the part of the item. It is the only state in a part name, because a page cannot otherwise select the state of an item inside a shadow root |
mbx-drm-badge |
icon, tooltip, tooltip-title, tooltip-text |
mbx-error-screen |
box, title, detail, category, separator, code, message, actions, retry, diagnostics |
Part names are public API. A release can add names. A name is only renamed in a major version.
Font size scaling
Every size in the controls is an em of the player’s font size, which is 16 pixels. One rule scales the whole interface: the buttons, the bar, the text, the menus.
mattebox-player {
font-size: 20px;
}
Borders and outlines stay one or two pixels at every size.
Layout tiers: compact, regular, wide

The player measures its own box and sets layout on itself. The controls
draw for that tier. The tier depends on the player’s box, not on the
screen: a small embed on a desktop page is compact, and a phone in
fullscreen is not.
| Tier | When | What the controls do |
|---|---|---|
compact |
Under 480 pixels wide, or under 320 high | One time readout, the time left. The title is one line at the top. Menus and the playlist open as sheets from the bottom of the player, over the controls. A menu’s first row is the way back |
regular |
Between the two | The design at 16 pixels |
wide |
From 1280 pixels wide and 700 high | The same design at 20 pixels, for a TV or a fullscreen |
You write the same markup for all three. A stylesheet reads the tier from the player, and every control carries it too:
mattebox-player[layout="compact"] mbx-skip-button {
display: none;
}
To fix the tier, write the attribute. The player then leaves it alone. Remove it to hand it back.
<mattebox-player layout="compact" src="…"></mattebox-player>
A font size of your own on the player wins over the tier’s.
The drawer
On a compact player, a menu or the playlist is a sheet inside the player.
A small player leaves a list little room. With drawer on the player,
they open in a drawer over the page, from the bottom of the viewport.
<!-- Every menu and the playlist, but not the speed menu. -->
<mattebox-player drawer controls="custom" src="…">
<mbx-control-bar>
<mbx-speed-menu drawer="off"></mbx-speed-menu>
</mbx-control-bar>
</mattebox-player>
<!-- The playlist alone. -->
<mattebox-player controls="custom" src="…">
<mbx-playlist drawer></mbx-playlist>
</mattebox-player>
- Without the attribute, the sheet stays inside the player. This is the default.
- The attribute on a menu or on
<mbx-playlist>sets it for that control alone, and wins over the player’s. drawer="off"on a control keeps its sheet inside a player that hasdrawer.- The attribute acts on a compact player only. A larger player keeps its popups over the picture.
- The drawer is as wide as the viewport, up to 30em, and at most 80% of its height.
- Escape closes it. So does a press on the dimmed page.
- The page behind it does not scroll while it is open.
The drawer is a <dialog> that the control opens with showModal(), in its
own shadow root. The browser draws it over the whole page and keeps the
focus inside it. The rest of the page is inert while it is open, and the
video keeps playing.
- The player adds nothing to the body of your page, and no
z-indexof your page applies. - The parts keep their names.
::part(popup)and::part(item)style a menu in the drawer, and::part(header)and::part(list)style the playlist. The dialog is thedrawerpart. - The custom properties of the player apply in the drawer.
- A player in an iframe shows the drawer over the iframe, not over the page around it.
showModal()needs Chrome 37, Safari 15.4 or Firefox 98. An older browser keeps the sheet inside the player.
A control of your own shows its nodes in the drawer with
player.drawer(nodes, options). The nodes are siblings in the control’s
shadow root. options.label is the drawer’s accessible name, and
options.dismiss runs when the viewer asks to leave. The call returns the
function that closes the drawer and puts the nodes back. It returns null
when there is no drawer, and the control then draws its own sheet.
const close = player.drawer([list], { label: 'Episodes', dismiss: () => close?.() });
CSS custom properties
Custom properties set on the player are inherited by every control:
--mbx-surface, --mbx-text, --mbx-muted, --mbx-accent, --mbx-error,
--mbx-radius, --mbx-gap, --mbx-pad, --mbx-font, --mbx-live,
--mbx-preview-width (in pixels, 10em by default), --mbx-menu-max-height (in pixels, 22em by default), --mbx-tooltip (none hides the tooltips), --mbx-blocked (the dashes of a blocked range), --mbx-spot (the ticks of the spots).
The shadow roots are open. When ::part() is not enough, a page adds a
stylesheet inside a control: control.shadowRoot.append(style) in every
browser, or adoptedStyleSheets in a modern one.
The <video> is in light DOM, so the page styles it directly. By default
it takes the full width at 16:9 until the media’s own ratio is known, so
the box does not change size when the metadata arrives. A page that knows
the ratio of its media sets aspect-ratio on the video.
The box of the player is black, and the picture is centred in it.
- With a height or an
aspect-ratioon the player,object-fit: containletterboxes or pillarboxes the picture inside the box. The bar stays at the bottom of the box, as in fullscreen. - Without a height, the box is as tall as the picture and no black shows.
mattebox-player { background: … }changes the colour.
Browser support
The player is a custom element, so it needs Custom Elements v1: Chrome 54, Safari 10.1, Firefox 63, Edge 79. Every browser has Shadow DOM v1 at or before those versions.
::part() needs Chrome 73, Safari 13.1, Firefox 72. An older browser still
applies the custom properties above.
The engine supports older browsers than the player: it needs ES2015 only.
A page for a browser the player does not support takes
@mattebox/player-core and writes its own UI.
Lifecycle
disconnectedCallback disposes the session. Reconnecting loads src
again.
- A move is no removal. The player waits a microtask, as HTML’s media element waits for a stable state, and disposes the session only if it is still out of the document.
- A page can move the player into place and set its source in the same task.
A control attaches when it is connected inside a player, and detaches when it is removed. A framework that reorders or replaces children is therefore safe.
Example
A player with its own bar in Catalan, its own play icons, and a control the page wrote.
<mattebox-player src="https://example.com/vod/master.m3u8" controls="custom">
<mbx-start-button label-play="Reproduir"></mbx-start-button>
<mbx-error-screen label-title="Error de reproducció" label-retry="Torna-ho a provar"></mbx-error-screen>
<mbx-control-bar>
<mbx-current-time></mbx-current-time>
<mbx-seek-bar label="Cerca" label-of="{current} de {duration}"></mbx-seek-bar>
<mbx-play-button label-play="Reproduir" label-pause="Pausa">
<svg slot="icon-play" viewBox="0 0 24 24"><path d="M8 5v14l11-7z" /></svg>
<svg slot="icon-pause" viewBox="0 0 24 24"><path d="M6 5h4v14H6zm8 0h4v14h-4z" /></svg>
</mbx-play-button>
<mbx-volume>
<mbx-mute-button label-mute="Silencia" label-unmute="Activa el so"></mbx-mute-button>
<mbx-volume-slider label="Volum"></mbx-volume-slider>
</mbx-volume>
<mbx-spacer></mbx-spacer>
<my-share-button></my-share-button>
<mbx-fullscreen-button label-enter="Pantalla completa" label-exit="Surt"></mbx-fullscreen-button>
</mbx-control-bar>
</mattebox-player>
<script type="module">
import '@mattebox/player';
class MyShareButton extends HTMLElement {
async connectedCallback() {
await customElements.whenDefined('mattebox-player');
const player = this.closest('mattebox-player');
const button = document.createElement('button');
button.type = 'button';
button.setAttribute('aria-label', 'Comparteix');
button.textContent = '↗';
button.addEventListener('click', () => {
navigator.share({ url: player.getAttribute('src') });
});
this.append(button);
}
}
customElements.define('my-share-button', MyShareButton);
</script>