Skip to content
FrameworkStyle

createPlayer

Factory function that creates a typed player element and controller for HTML custom elements

Import

import { createPlayer } from "@videojs/html";
import { videoFeatures } from "@videojs/html/video";

createPlayer is the entry point for custom HTML player compositions. It accepts a features array and returns the configured PlayerElement, a PlayerController already bound to that player, and playerContext as a lower-level escape hatch. Import ContainerElement separately when you need a custom container.

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

const { PlayerElement: VideoPlayerElement, PlayerController } = createPlayer({
  features: videoFeatures,
});

customElements.define('video-player', VideoPlayerElement);

// Control element with selector
class PlayButton extends UIElement {
  #playback = new PlayerController(this, selectPlayback);
}

PlayerElement and PlayerController are scoped to the created player’s feature set. The element owns its store and attachment lifecycle; the configured controller does not need a context argument. ContainerElement consumes the shared player context, so the same class works with any created player.

Use split elements (recommended for reusable skins/layouts):

import { ContainerElement, createPlayer } from '@videojs/html';
import { videoFeatures } from '@videojs/html/video';

const { PlayerElement: PlayerRoot } = createPlayer({ features: videoFeatures });

class PlayerRegion extends ContainerElement {}

Examples

Basic Usage

Play Pause
<demo-video-player class="demo-video-player">
  <media-container>
    <video src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4" autoplay muted playsinline></video>
    <demo-play-toggle class="media-play-button">
      <span class="paused">Play</span>
      <span class="playing">Pause</span>
    </demo-play-toggle>
  </media-container>
</demo-video-player>

API Reference

Video

Creates a typed HTML player class and bound controller.

Parameters

ParameterTypeDefaultDetails
config*{ features: VideoFeatures }

Return Value

PropertyTypeDetails
PlayerElementfunction
PlayerControllerobject
playerContextContext<typeof PLAYER_CONTEXT_KEY, PlayerContextValue<VideoPlayerStore>>

Audio

Creates a typed HTML audio player class and bound controller.

Parameters

ParameterTypeDefaultDetails
config*{ features: AudioFeatures }

Return Value

PropertyTypeDetails
PlayerElementfunction
PlayerControllerobject
playerContextContext<typeof PLAYER_CONTEXT_KEY, PlayerContextValue<AudioPlayerStore>>

Generic

Creates a typed HTML player class with custom features.

Parameters

ParameterTypeDefaultDetails
config*{ features: Features }

Return Value

PropertyTypeDetails
PlayerElementfunction
PlayerControllerobject
playerContextContext<typeof PLAYER_CONTEXT_KEY, PlayerContextValue<PlayerStore<Features>>>