Blocks and markers
@mattebox/player@0.18.0Needs @mattebox/player-core ^0.11.0 and mattebox ^0.21.0.
Markers and blocks are data from your content API that a stream does not carry.
- A marker is a time range of the programme with a kind: opening credits, closing credits, or a range that must not play.
- A block stops the load and shows a title and a message in the player’s locale, such as a geoblock.
A connector can return both, and the player applies them for you.
Markers: player.markers
Markers are ranges of the media that you name from your own content API: the opening and closing credits, a recap, or a part that must not play. No stream format carries credits as a standard, so the page sets them. They work the same for an engine session and a native one.
player.markers.set([
{ start: 0, end: 52, kind: 'opening-credits' },
{ start: 600, end: 630, kind: 'blocked', label: 'Not available for legal reasons' },
{ start: 1380, end: 1440, kind: 'closing-credits' },
]);
kind |
What happens |
|---|---|
opening-credits |
<mbx-marker-button> shows “Skip intro” inside the range |
closing-credits |
<mbx-marker-button> shows “Skip credits” inside the range, unless the player carries upnext |
blocked |
Playback never enters the range: the player moves past its end. The seek bar shows a hollow in the track there, and its preview shows the label, or “Not available” |
| Any other value | <mbx-marker-button> shows “Skip” and the marker’s label |
- Set the markers after
src: a new source clears them. player.markers.listgives them by start, andplayer.markers.within(time)the ones that hold a time.markerschangefires when the list changes, with the list asdetail.blockedfires each time the player moves past a blocked range, with the marker asdetail. Show a notice there if your viewers need one.- A
labeltakes a string or an object of strings by language tag, as a block’s title does. See Blocks.
Blocks: player.block()
block() stops the load and shows why the programme does not play, such
as a geographic or an age restriction. Pass the title and the message:
player.block({
title: { en: 'Not available', de: 'Nicht verfügbar', fr: 'Non disponible' },
message: {
en: 'This content is not available outside Switzerland.',
de: 'Dieser Inhalt ist ausserhalb der Schweiz nicht verfügbar.',
fr: 'Ce contenu n’est pas disponible hors de Suisse.',
},
});
<mbx-error-screen>shows the title and the message, with no retry. Under native controls, the row under the video shows them.titleandmessageeach take a string, or an object of strings by language tag. The player picks an entry in this order: its full tag, the language subtag,en, then the first entry. The text updates whenlanguagechanges, as the labels do.- Without a
title, the title is the player’s “Not available” message, in the player’s locale. - A new
srcorsourcesclears the block, as it clears the markers.unblock()clears it too. Nothing plays until a source loads: set one, or callretry(). player.blockedis the block, or null, andblockchangefires when it changes.- The live region says the title and the message, unless an
<mbx-error-screen>in the player says them.
Example
A page that asks its API about an episode, and either blocks it or plays it with its credits:
const player = document.querySelector('mattebox-player');
const episode = await fetch('/api/episodes/ep-1042').then((r) => r.json());
if (episode.blockReason === 'GEOBLOCK') {
player.block({
message: {
en: 'This programme is only available in Switzerland.',
de: 'Diese Sendung ist nur in der Schweiz verfügbar.',
},
});
} else {
player.setAttribute('src', episode.hls);
// After the source: a new source clears the markers.
player.markers.set([
{ start: 0, end: episode.introEnd, kind: 'opening-credits' },
{ start: episode.creditsStart, end: episode.duration, kind: 'closing-credits' },
]);
}