Factory function that creates a typed player store, mixins, and controller for HTML custom elements.
createPlayer is the entry point for setting up a Video.js player with HTML custom elements. It accepts a configuration object with a features array and returns a typed PlayerController, context, ProviderMixin, ContainerMixin, and a create store factory.
Array of feature objects that define the capabilities of the player store. Use videoFeatures from @videojs/html/video for a standard video player, audioFeatures from @videojs/html/audio for audio-only, or compose your own feature array.
Mixin function that adds store ownership and context provision to a base element class. The resulting element creates the store lazily and publishes it to descendants. See ProviderMixin.
Mixin function that adds media discovery and auto-attachment to a base element class. The resulting element watches for <video> and <audio> children and calls store.attach(). See ContainerMixin.
Use separate elements for the store owner and the media region. This pattern gives the most flexibility for complex layouts.
player.ts
import { createPlayer, MediaElement, selectPlayback } from '@videojs/html';import { videoFeatures } from '@videojs/html/video';const { ProviderMixin, ContainerMixin, PlayerController, context } = createPlayer({ features: videoFeatures,});// Provider element: owns the store and provides it to descendantsclass VideoPlayer extends ProviderMixin(MediaElement) {}customElements.define('video-player', VideoPlayer);// Container element: discovers and attaches the media elementclass VideoRegion extends ContainerMixin(MediaElement) {}customElements.define('video-region', VideoRegion);// Control element: subscribes to a slice of player stateclass PlayButton extends MediaElement { #playback = new PlayerController(this, context, selectPlayback);}customElements.define('play-button', PlayButton);
Use the create factory to create a store instance outside the custom element tree.
player.ts
import { createPlayer } from '@videojs/html';import { videoFeatures } from '@videojs/html/video';const { create } = createPlayer({ features: videoFeatures });const store = create();await store.play();store.destroy();
createPlayer returns the same PlayerController class regardless of call site. The context object is what scopes controllers to the correct provider. Keep the context reference from createPlayer and pass it to every PlayerController instance you create.