Skip to content
FrameworkStyle

PlayerController

Reactive controller for accessing player store state in HTML custom elements

Import

import { PlayerController } from "@videojs/html/video";

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.

import { UIElement, selectPlayback } from '@videojs/html';
import { PlayerController } from '@videojs/html/video';

class PlayButtonElement extends UIElement {
  readonly #playback = new PlayerController(this, selectPlayback);
}

Examples

Basic Usage

Paused: Yes | Time: 0.0s | Volume: 100%
<demo-ctrl-player class="demo-ctrl-player">
  <media-container>
    <video src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4" autoplay muted playsinline></video>
    <div class="panel">
      <demo-ctrl-actions class="actions">
        <button type="button" class="play">Play</button>
        <button type="button" class="pause">Pause</button>
        <button type="button" class="volume">50% Volume</button>
      </demo-ctrl-actions>
      <demo-ctrl-state class="state">
        <span class="text">Paused: Yes | Time: 0.0s | Volume: 100%</span>
      </demo-ctrl-state>
    </div>
  </media-container>
</demo-ctrl-player>

API Reference

Overload 1

Parameters

ParameterTypeDefaultDetails
host*object
context*Context<typeof PLAYER_CONTEXT_KEY, PlayerContextValue<Store>>

Return Value

PropertyTypeDetails
valueResult | undefined
displayNamestring | undefined
hostConnected(() => void)
hostDisconnected(() => void)

Overload 2

Parameters

ParameterTypeDefaultDetails
host*object
context*Context<typeof PLAYER_CONTEXT_KEY, PlayerContextValue<Store>>
selector*Selector<InferStoreState<Store>, Result>

Return Value

PropertyTypeDetails
valueResult | undefined
displayNamestring | undefined
hostConnected(() => void)
hostDisconnected(() => void)