FrameworkStyle

createPlayer

Factory function that creates a player instance with typed store, mixins, and controller for HTML custom elements

Import

import { createPlayer, features } from '@videojs/html';

Usage

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 everything needed to build a player: a pre-composed PlayerElement, typed PlayerController, context, individual mixins, and a create factory.

import { createPlayer, features, MediaElement } from '@videojs/html';

const {
  PlayerElement,
  PlayerController,
  context,
  PlayerMixin,
  ProviderMixin,
  ContainerMixin,
  create,
} = createPlayer({ features: features.video });

// Register the pre-composed player element
customElements.define('video-player', PlayerElement);

The simplest approach is to register PlayerElement directly. For custom behavior, use the individual mixins to compose your own element classes.

Examples

Basic Usage

Play Pause
<demo-video-player class="html-create-player-basic">
    <video
        src="https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4"
        autoplay
        muted
        playsinline
    ></video>
    <demo-play-toggle class="html-create-player-basic__button">
        <span class="show-when-paused">Play</span>
        <span class="show-when-playing">Pause</span>
    </demo-play-toggle>
</demo-video-player>

API Reference

Overload 1

Creates a player factory with typed store, mixins, and controller.

Parameters

Parameter Type Default
config* CreatePlayerConfig<VideoFeatures>

Return Value

Property Type
context PlayerContext<Store>
create () => Store
PlayerController PlayerController.Constructor<Store>
PlayerElement PlayerElementConstructor<Store>
PlayerMixin PlayerMixin<Store>
ProviderMixin ProviderMixin<Store>
ContainerMixin ContainerMixin<Store>

Overload 2

Parameters

Parameter Type Default
config* CreatePlayerConfig<AudioFeatures>

Return Value

Property Type
context PlayerContext<Store>
create () => Store
PlayerController PlayerController.Constructor<Store>
PlayerElement PlayerElementConstructor<Store>
PlayerMixin PlayerMixin<Store>
ProviderMixin ProviderMixin<Store>
ContainerMixin ContainerMixin<Store>

Overload 3

Parameters

Parameter Type Default
config* CreatePlayerConfig<Features>

Return Value

Property Type
context PlayerContext<Store>
create () => Store
PlayerController PlayerController.Constructor<Store>
PlayerElement PlayerElementConstructor<Store>
PlayerMixin PlayerMixin<Store>
ProviderMixin ProviderMixin<Store>
ContainerMixin ContainerMixin<Store>
VideoJS