Shaka Player
The ShakaPlayer class is a subclass of the Shaka player that keeps the remote player synchronized automatically.
Constructor
- constructor(mediaElement) — pass in the video element to use in the local player
Functions
These functions are overridden from the Shaka superclass:
(async) load(url)
— loads a video, but does not play it automaticallyconfigureDrm(server)
— allows you specify the DRM server
The class listens for events from the media element to keep the remote player in sync. For example, if you play or pause the video, it will automatically play or pause in the remote player. It automatically keeps the current time in the remote player in sync with the browser. That way when you switch between foreground and background mode, the video will play continuously.
Usage
import { init, uiReady, ShakaPlayer, lifecycle } from "senza-sdk";
const TEST_VIDEO = "https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd";
let player;
window.addEventListener("load", async () => {
try {
await init();
player = new ShakaPlayer(video);
await player.load(TEST_VIDEO);
await video.play();
uiReady();
} catch (error) {
console.error(error);
}
});
async function toggleBackground() {
if (lifecycle.state == lifecycle.UiState.BACKGROUND) {
await lifecycle.moveToForeground();
} else {
await lifecycle.moveToBackground();
}
}
Updated about 1 month ago