Casting
@mattebox/player-cast@0.7.0Needs @mattebox/player >=0.15.0 and mattebox ^0.17.0.
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 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 and names the device: “Casting to Living room”. 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 audio, subtitles and speed 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} |
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.