THEOplayer / web-ui

UI component library for the THEOplayer Web SDK
https://www.theoplayer.com/docs/open-video-ui/web/
MIT License
10 stars 0 forks source link
theoplayer video-player web-components

THEOplayer Open Video UI for Web

NPM version Build status API docs GitHub issues

A component library for building a world-class video player experience powered by the THEOplayer Web SDK.

Screenshot on desktop Screenshot on mobile
Desktop Mobile

Motivation

The current THEOplayer Web SDK comes with a built-in UI based on video.js through the Player constructor. This new UI aims to solve some limitations from the old approach:

[!NOTE]
THEOplayer Open Video UI for Web currently exists separately from the old THEOplayer UI. In the future, we hope to deprecate and remove the old UI, and ship this new UI as default UI for the THEOplayer Web SDK.

Installation

  1. This project requires the THEOplayer Web SDK to be installed.
    npm install theoplayer

    You can also install a different variant of the THEOplayer npm package if you don't need all features, as long as it's aliased as theoplayer.

    npm install theoplayer@npm:@theoplayer/basic-hls
  2. Install the Open Video UI for Web.
    npm install @theoplayer/web-ui
  3. Add @theoplayer/web-ui to your app:
    • Option 1: in your HTML.
      <script src="https://github.com/THEOplayer/web-ui/raw/develop/path/to/node_modules/theoplayer/THEOplayer.chromeless.js"></script>
      <script src="https://github.com/THEOplayer/web-ui/raw/develop/path/to/node_modules/@theoplayer/web-ui/dist/THEOplayerUI.js"></script>
    • Option 2: in your JavaScript.
      import { DefaultUI } from '@theoplayer/web-ui';

      Open Video UI will import THEOplayer from theoplayer/chromeless. If you're using a bundler such as Webpack or Rollup, this dependency should automatically get bundled with your web app. Alternatively, you can use an import map to let the browser resolve it:

      <script type="importmap">
          {
              "imports": {
                  "theoplayer/chromeless": "/path/to/node_modules/theoplayer/THEOplayer.chromeless.esm.js"
              }
          }
      </script>
      <!-- Import maps polyfill for browsers without import maps support (e.g. Safari 16.3) -->
      <script async src="https://ga.jspm.io/npm:es-module-shims@1.8.0/dist/es-module-shims.js" crossorigin="anonymous"></script>
      <script type="module" src="https://github.com/THEOplayer/web-ui/raw/develop/path/to/my_app.js"></script>

Usage

Default UI

<theoplayer-default-ui> provides a fully-featured video player experience with minimal setup, and allows for small customizations such as changing colors or fonts.

See default-ui/demo.html for a complete example.

Custom UI

If you want to fully customize your video player layout, you can use a <theoplayer-ui> instead.

<theoplayer-ui
    configuration='{"libraryLocation":"/path/to/node_modules/theoplayer/","license":"your_theoplayer_license_goes_here"}'
    source='{"sources":{"src":"https://example.com/stream.m3u8"}}'
>
    <!-- Choose your own layout using the provided components (or your own!) -->
    <theoplayer-control-bar>
        <theoplayer-time-range></theoplayer-time-range>
    </theoplayer-control-bar>
    <theoplayer-control-bar>
        <theoplayer-play-button></theoplayer-play-button>
        <theoplayer-mute-button></theoplayer-mute-button>
        <theoplayer-volume-range></theoplayer-volume-range>
    </theoplayer-control-bar>
</theoplayer-ui>

See custom-ui/demo.html for a complete example.

Legacy browser support

By default, Open Video UI for Web targets modern browsers that support modern JavaScript syntax (such as async/await) and native Custom Elements. This keeps the download size small, so your viewers can spend less time waiting for your page to load and start watching their video faster.

On older browsers (such as Internet Explorer 11 and older smart TVs), you need to load a different version of the Open Video UI that uses older JavaScript syntax. You also need to load additional polyfills for missing features such as Promises or Custom Elements. We recommend the Cloudflare mirror of Polyfill.io and Web Components Polyfills for these.