@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.
Prerequisites
@videojs/html installed (see Installation).
Quick start
Import the custom elements
Each element registers itself as a global custom element via a side-effect import. Import the player, skin, and CSS:
index.ts
Available presets
Each preset provides a player element, one or more skin elements, and an optional media element:| Preset | Player element | Skin elements | Media element |
|---|---|---|---|
/video | <video-player> | <video-skin>, <video-minimal-skin> | <video> |
/audio | <audio-player> | <audio-skin>, <audio-minimal-skin> | <audio> |
/background | <background-video-player> | <background-video-skin> | <background-video> |
Audio preset example
Background video preset example
Individual UI elements
You can import individual UI elements from@videojs/html/ui/* to compose your own layout without using a preset skin:
| Element | Purpose |
|---|---|
<media-play-button> | Play / pause toggle |
<media-mute-button> | Mute / unmute toggle |
<media-volume-slider> | Volume level slider |
<media-time-slider> | Seek / progress slider |
<media-fullscreen-button> | Fullscreen toggle |
<media-pip-button> | Picture-in-picture toggle |
<media-seek-button> | Jump forward or backward by seconds |
<media-playback-rate-button> | Cycle through playback rates |
<media-captions-button> | Toggle captions |
<media-buffering-indicator> | Shown while buffering |
<media-container> | Layout wrapper for media + controls |
<media-controls> | Controls bar |
State reflection via data-* attributes
Custom elements reflect player state asdata-* attributes on the element. Use CSS to respond to state changes:
Access state in JavaScript with PlayerController
UsePlayerController to read player state and call actions from JavaScript. Import a feature selector such as selectPlayback to subscribe to a specific slice of state:
Create a custom player element
UsecreatePlayer() to define a player element with a specific set of features, then extend ProviderMixin to register it as a custom element:
Next steps
Media sources
Add HLS, DASH, and other streaming formats.
Custom features
Compose and extend the player’s feature set.
Custom skins
Build your own skin from individual UI elements.