Basic Usage

Basic usage of Shaka Player is very easy:

  1. Start with Welcome to Shaka Player and compile the library.
  2. Create a simple HTML page with a video or audio element.
  3. In your application's JavaScript -
    1. Install Shaka's polyfills.
    2. Check for browser support.
    3. Create a Player object to wrap the media element.
    4. Listen for errors.
    5. Load a manifest.
<!DOCTYPE html>
    <!-- Shaka Player compiled library: -->
    <script src="dist/shaka-player.compiled.js"></script>
    <!-- Your application source: -->
    <script src="myapp.js"></script>
    <video id="video"
           controls autoplay></video>
// myapp.js

const manifestUri =

function initApp() {
  // Install built-in polyfills to patch browser incompatibilities.

  // Check to see if the browser supports the basic APIs Shaka needs.
  if (shaka.Player.isBrowserSupported()) {
    // Everything looks good!
  } else {
    // This browser does not have the minimum set of APIs we need.
    console.error('Browser not supported!');

async function initPlayer() {
  // Create a Player instance.
  const video = document.getElementById('video');
  const player = new shaka.Player();
  await player.attach(video);

  // Attach player to the window to make it easy to access in the JS console.
  window.player = player;

  // Listen for error events.
  player.addEventListener('error', onErrorEvent);

  // Try to load a manifest.
  // This is an asynchronous process.
  try {
    await player.load(manifestUri);
    // This runs if the asynchronous load is successful.
    console.log('The video has now been loaded!');
  } catch (e) {
    // onError is executed if the asynchronous load fails.

function onErrorEvent(event) {
  // Extract the shaka.util.Error object from the event.

function onError(error) {
  // Log the error.
  console.error('Error code', error.code, 'object', error);

document.addEventListener('DOMContentLoaded', initApp);

That's it!