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, selectPlayback } from '@videojs/html';
import { videoFeatures } from '@videojs/html/video';

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

// Provider element: owns the store, provides context to descendants
class VideoPlayer extends ProviderMixin(MediaElement) {}
customElements.define('video-player', VideoPlayer);

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

PlayerController, ProviderMixin, and ContainerMixin are intended for controller hosts and custom-element composition. Keep wiring minimal in utility examples, and build concrete elements where needed.

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

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

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

class PlayerRoot extends ProviderMixin(MediaElement) {}
class PlayerRegion extends ContainerMixin(MediaElement) {}

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

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

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

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

Examples

Basic Usage

Play Pause
<demo-video-player class="html-create-player-basic">
    <media-container>
        <video
            slot="media"
            src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/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>