FrameworkStyle

createPlayer

Factory function that creates a player instance with typed 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.

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

const {
  PlayerController,
  context,
  ProviderMixin,
  ContainerMixin,
  create,
} = createPlayer({ features: videoFeatures });

// Provider element: owns and publishes the store
class VideoPlayer extends ProviderMixin(MediaElement) {}

// Container element: discovers <video>/<audio> and calls store.attach()
class MediaContainer extends ContainerMixin(MediaElement) {}

customElements.define('video-player', VideoPlayer);
customElements.define('media-container', MediaContainer);

Composition patterns

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

const {
  PlayerController,
  context,
  ProviderMixin,
  ContainerMixin,
} = createPlayer({ features: videoFeatures });

class VideoPlayer extends ProviderMixin(MediaElement) {}
class MediaContainer extends ContainerMixin(MediaElement) {}

Use a single composed element when the same element should both own the store and attach media:

const { ProviderMixin, ContainerMixin } = createPlayer({ features: videoFeatures });

class VideoPlayer extends ProviderMixin(ContainerMixin(MediaElement)) {}

When using the built-in defined elements (@videojs/html/video/player, etc.), media-container is expected as the first child and UI should live inside it.

Examples

Basic Usage

Play Pause
<demo-video-player class="html-create-player-basic">
    <media-container>
        <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>
    </media-container>
</demo-video-player>

API Reference

Video

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 function
PlayerController PlayerController.Constructor<Store>
ProviderMixin ProviderMixin<Store>
ContainerMixin ContainerMixin<Store>

Audio

Creates a player factory for audio media.

Parameters

Parameter Type Default
config* CreatePlayerConfig<AudioFeatures>

Return Value

Property Type
context PlayerContext<Store>
create function
PlayerController PlayerController.Constructor<Store>
ProviderMixin ProviderMixin<Store>
ContainerMixin ContainerMixin<Store>

Generic

Creates a player factory with custom features.

Parameters

Parameter Type Default
config* CreatePlayerConfig<Features>

Return Value

Property Type
context PlayerContext<Store>
create function
PlayerController PlayerController.Constructor<Store>
ProviderMixin ProviderMixin<Store>
ContainerMixin ContainerMixin<Store>
VideoJS