Use this file to discover all available pages before exploring further.
@videojs/html provides a set of custom elements that work in any browser without a JS framework. Each element registers itself via a side-effect import.
Custom elements reflect player state as data-* attributes on the element. Use CSS to respond to state changes:
/* Show play icon only when paused */media-play-button .play-icon { display: none; }media-play-button[data-paused] .play-icon { display: inline; }/* Show pause icon only when playing */media-play-button .pause-icon { display: none; }media-play-button:not([data-paused]) .pause-icon { display: inline; }/* Hide fullscreen button on platforms that don't support it */media-fullscreen-button[data-availability="unsupported"] { display: none; }
Use PlayerController to read player state and call actions from JavaScript. Import a feature selector such as selectPlayback to subscribe to a specific slice of state:
import { createPlayer, playback, volume, time, MediaElement } from '@videojs/html';import { selectPlayback } from '@videojs/html';const { ProviderMixin, context } = createPlayer({ features: [playback, volume, time],});class PlayToggle extends HTMLElement { readonly #playback = new PlayerController(this, context, selectPlayback); connectedCallback() { this.addEventListener('click', () => { const state = this.#playback.value; if (state?.paused) { state.play(); } else { state?.pause(); } }); }}