GuideGetting Started
Build your own UI component
Create custom player controls that read state, dispatch actions, and stay accessible.
Custom components subscribe to player state and dispatch actions, like built-in controls.
You might not need a custom component
Before building from scratch, check if an existing approach covers your use case:
- Restyle a control: use CSS custom properties and data attributes. See UI components.
- Rearrange or remove controls: add the skin source to your project, then modify it. See Customize skins.
Build a custom component when you need new behavior, a new state display, or integration with an external system.
Place your component in the player
Your element needs to be inside <video-player> to access state. Place it inside <media-container> if it should also participate in fullscreen and respond to user activity. <video-skin> slots its children into <media-container>, so a child of the skin works:
Extend UIElement from @videojs/html so PlayerController can schedule DOM updates when state changes:
If your element starts listeners, observers, or other work, stop it in disconnectedCallback() and call the superclass lifecycle methods so inherited cleanup runs too. The browser can connect and disconnect the same element many times.
Full example
A “skip intro” button that appears during the first 30 seconds of playback and seeks past the intro when clicked.
Your element needs to be inside <video-player> to access state. Place it inside <media-container> if it should also participate in fullscreen and respond to user activity. <video-skin> slots its children into <media-container>, so a child of the skin works:
How it works
Custom components read player state and dispatch actions through features. Each feature exposes a set. Here are some features you might reach for first:
The API reference lists every feature with the state and actions it adds.
Extend UIElement from @videojs/html so PlayerController can schedule DOM updates when state changes, and access state and actions with a feature selector:
Each selector returns both state and actions for that feature. Use separate controllers when you need multiple features (the full example demonstrates this).
Without a selector, PlayerController returns the full store without subscribing to changes. Create the controller with the typed context that createPlayer returns — the shared playerContext types the store’s members as unknown — and guard the value, which stays undefined until a player provides the store:
Custom controls also need real button semantics — the examples above set the accessible name, keyboard focus, and (because a custom element is not a native <button>) the ARIA button pattern by hand.
Availability and constraints
- Features are configured per player, so a feature your component asks for may not be present. Selectors return
undefinedfor a missing feature; guard the value before using it, as the example does. - Volume, fullscreen, picture-in-picture, and remote playback also expose an
*Availabilityproperty ('available','unavailable', or'unsupported') for hiding controls the platform does not support. See Features for details.
Common variations
Before building from scratch, check if an existing approach covers your use case. Build a custom component when you need new behavior, a new state display, or integration with an external system.
Restyle a control
Use CSS custom properties and data attributes. See UI components.
Rearrange or remove controls
Add the skin source to your project and modify it. See Customize skins.
Troubleshooting
State and actions are typed as unknown
You’re using the shared playerContext, which doesn’t know which features your player has. Use the typed context returned by createPlayer.
The component renders but never updates
The element sits outside <video-player>, or the class doesn’t extend UIElement, so PlayerController has nothing to schedule updates on.
Related pages
API
- PlayerControllerReactive controller for accessing player store state in HTML custom elements
- createPlayerFactory function that creates a typed player element and controller for HTML custom elements
- media-containerThe player's visual and interaction surface for layout, fullscreen, focus, and user activity.