Player basics ************* Player basics for PRESTOplay for Web Apps. Covers a minimal playback UI (container, poster, play button) and common PlayerConfiguration options (source, stream type, start time, volume, muted). Code samples: * Simple UI (https://raw.githubusercontent.com/castlabs/prestoplay-web-code-samples/refs/heads/main/examples/player/simple_ui.js): a container around the video, a poster shown before playback starts, and a big play button. * Player configuration (https://raw.githubusercontent.com/castlabs/prestoplay-web-code-samples/refs/heads/main/examples/player/configuration.js): sets the start time, volume, and muted state from a form. * React integration (https://raw.githubusercontent.com/castlabs/prestoplay-web-code-samples/refs/heads/main/examples/react/react.html): a React player component with play/pause, a seek bar, and fullscreen. Simple UI example ================= The Simple UI sample (https://raw.githubusercontent.com/castlabs/prestoplay-web-code-samples/refs/heads/main/examples/player/simple_ui.js) shows a minimal playback UI: a container around the video element, a poster image shown until playback starts, and a big play button. The container is passed to the player as "containerEl", so the poster and the button can sit on top of the video. Playback and basic configuration ================================ "PlayerConfiguration" (https://players.castlabs.com/web/latest/docs/api/clpp.utils.PlayerConfiguration.md) is passed to the "Player" (https://players.castlabs.com/web/latest/docs/api/clpp.Player.md) constructor. Source and per-load options are passed to "Player.open" (https://players.castlabs.com/web/latest/docs/api/clpp.Player.md#open). Loading content --------------- Pass a configuration object with a "source" property: player.open({ source: 'https://example.com/manifest.mpd', }); "source" also accepts an array of URLs. The player tries them in order and plays the first one it can play on the current platform: player.open({ source: [ 'https://example.com/manifest1.mpd', 'https://example.com/manifest2.mpd', 'https://example.com/master.m3u8', ], }); Supported formats ----------------- Supported types are "clpp.Type.DASH", "clpp.Type.HLS", "clpp.Type.SMOOTH_STREAMING", and "clpp.Type.MP4". If the format can't be deduced from the file extension, specify it explicitly as "type": player.open({ source: 'https://example.com/manifest.foo', type: clpp.Type.DASH, }); Start time, volume, and muted state ----------------------------------- player.open({ source: 'https://example.com/manifest.mpd', startTime: 300, // start 5 minutes in, VOD only volume: 0.5, autoplay: true, muted: true, }); For live content, the player starts at the live edge by default. See Tracks and languages for setting the initial audio and text language. React integration ================= React integration: create the "Player" (https://players.castlabs.com/web/latest/docs/api/clpp.Player.md) in a "useEffect()" hook on mount and call "Player.destroy" (https://players.castlabs.com/web/latest/docs/api/clpp.Player.md#destroy) in its cleanup function. Load new content with "Player.open" (https://players.castlabs.com/web/latest/docs/api/clpp.Player.md#open) when the "src" prop changes. The React integration sample (https://raw.githubusercontent.com/castlabs/prestoplay-web-code-samples/refs/heads/main/examples/react/react.html) covers: * Creating the player on mount and destroying it on unmount * Loading content when a prop changes * A play/pause button driven by "clpp.events.STATE_CHANGED" * Fullscreen on the component's container element * A seek bar based on "Player.getSeekRange" (https://players.castlabs.com/web/latest/docs/api/clpp.Player.md#getSeekRange), which also supports live content