ReferencePlayer
PlayerController
Reactive controller for accessing player store state in HTML custom elements
Import
PlayerController is a reactive controller that consumes the player store from playerContext. Without a selector it returns the store instance directly (no subscription — use this for actions). With a selector it returns the selected value and subscribes to changes, triggering a host update on shallow-equal change. Access the current value via .value, which returns undefined until connected to a player.
The controller exported by each preset, or returned by createPlayer, is already bound to that player’s context, so pass only the host and optional selector. The lower-level PlayerController exported from @videojs/html accepts the context as its second argument; its constructor signatures are documented below.
The host must be a reactive controller host, such as a subclass of UIElement, so the controller can request updates.
Player context
playerContext is the context every player element provides to its descendants, whether the element comes from a preset or from createPlayer. PlayerController requests it from its host when the host connects, and the nearest ancestor player answers with its store. An element outside a player receives nothing, so value stays undefined.
Pass playerContext to the PlayerController exported from @videojs/html:
With a selector, the selector types the value. Without one, value is typed as the base player store, with no feature state or actions, because playerContext does not know the player’s features. For typed access, use the PlayerController that createPlayer returns, which is already bound to its player, or pass the context createPlayer returns, which is the same context as playerContext typed for its feature set: