Cast playlist

The SDK offers a higher-level alternative to the Cast queue APIs: CastPlaylist. It lets you manage a playlist from either the sender or receiver side with a common API.

Initialization

const player = new clpp.Player('video');
const castPlaylist = new clpp.cast.playlist.CastPlaylist(
  player,
  CHROMECAST_APP_ID,
  [
    { configuration: { source: '...' }, skippable: false },
    { configuration: { source: '...' }, skippable: true },
  ],
);

The SDK forbids skipping non-skippable items in the playlist. If you use the skippable property, reflect it in your sender UI.

Usage

Use CastPlaylist methods to read the current and full playlist state, and subscribe to change notifications:

castPlaylist.onPlaylistItemChange(updateUI);
castPlaylist.onPlaylistModified(updateUI);
castPlaylist.onCastStatusChanged(updateUI);

function updateUI() {
  const playlistItems = castPlaylist.getPlaylistItems();
  const currentIndex = castPlaylist.getCurrentIndex();
  playlistItems.forEach((item, index) => { ... });
}

Playing

Prepare the playlist:

castPlaylist.start();

Start playback:

castPlaylist.play();

Destroying and reusing the player

Destroy the CastPlaylist instance and reuse the player for a new casting session with the CastProxy API:

let castProxy = null;
async function startNewCastProxy() {
  // Stop casting first, if active
  if (castPlaylist.isCasting()) {
    castPlaylist.toggleCast();
  }
  castPlaylist.destroy();

  // Create a new CastProxy, load, and play
  castProxy = new clpp.cast.CastProxy(player, CHROMECAST_APP_ID);
  await player.open({
    source: '...',
    type: 'application/dash+xml',
  });
  player.play();
}
Next topic: AirPlay
Previous topic: Queuing