Core API

Everything in @playerstack/core.

Playerstack singleton

The entry point. Register plugins, then call define() to register the custom element.

import { Playerstack } from "@playerstack/core";

Playerstack.use(somePlugin).use(anotherPlugin).define();
Method Returns Description
use(plugin) Playerstack (chainable) Register a plugin. Throws on duplicate name
plugins() readonly PlayerstackPlugin[] Snapshot of registered plugins (read-only)
define() void Register <player-stack> custom element. Idempotent

PlayerstackPlugin

The interface every plugin implements:

interface PlayerstackPlugin {
  readonly name: string;
  init(ctx: PlayerstackContext): void | Promise<void>;
  destroy?(ctx: PlayerstackContext): void;
}

PlayerstackContext

What init and destroy receive:

interface PlayerstackContext {
  events: EventBus; // typed pub/sub
  container: HTMLElement; // the <player-stack> itself
  mediaPlayer: HTMLElement; // the inner <media-player>
  config: PlayerstackConfig;
}

Plugins read their slice of config and mutate mediaPlayer and container as needed. Use events to communicate with other plugins or your application.

EventBus

Strongly typed pub/sub.

const bus = createEventBus<{ "cta:click": { label: string; url: string } }>();

const unsubscribe = bus.on("cta:click", ({ label, url }) => {
  console.log(label, url);
});

bus.emit("cta:click", { label: "Buy", url: "..." });
unsubscribe();
// or:
const removed = bus.off("cta:click", handler); // returns boolean
Method Returns
on(name, handler) unsubscribe function
off(name, handler) boolean (was it removed?)
emit(name, payload) void

Handlers that throw don’t stop later handlers — errors are logged.

ConfigProvider

How config gets loaded for a <player-stack> element.

interface ConfigProvider {
  readonly name: string;
  load(element: HTMLElement): Promise<PlayerstackConfig>;
}

The default is createInlineConfigProvider(), which reads src, poster, title, preload attributes plus the data-config JSON attribute. JSON wins on merge when the player starts; a later change to one of those attributes (during or after start) overrides the JSON value.

Replace the default in a module that your entry file imports first:

// config-provider.ts
import { setConfigProviderForElement } from "@playerstack/core/element";
setConfigProviderForElement(myProvider);
// main.ts
import "./config-provider"; // must stay the first import
import { Playerstack } from "@playerstack/core";

@playerstack/core defines <player-stack> as soon as it is imported (plugins import it too), and players already on the page start with the provider installed at that moment. Install the provider from @playerstack/core/element in a module that is the first import of your entry file. The hosted playerstack.min.js always uses the default provider; a custom provider needs a custom build (see examples/12-sellf-integration).

See sellf-adapter for an example.

PlayerstackConfig

interface PlayerstackConfig {
  src: string; // required
  poster?: string;
  title?: string;
  preload?: "none" | "metadata" | "auto";
  lang?: string; // language of the control labels
  labels?: Record<string, string>; // labels for `lang`
  hls?: Record<string, unknown>; // hls.js options, see the sources plugin
  [key: string]: unknown; // plugin-specific slices
}

preload is applied before the media element connects. For native MP4, none defers loading until playback and disables automatic previews. Omit it to preserve the browser default. Preview autoplay also respects prefers-reduced-motion: reduce from the first connection. Third-party providers determine their own loading behavior.

Plugin-specific slices live alongside the core fields:

See each plugin’s docs for its slice schema.

Control labels

media-chrome ships English labels (more languages only as separate dictionaries, without Polish). To name the controls in your language, set lang and pass labels, keyed by the English media-chrome strings. Missing keys stay English; labels has no effect without lang. Labels are plain text; a value containing < is ignored. One language applies to the whole page, so use the same lang on every player. Plugin texts have their own options (replayLabel, skipLabel, emailGate.messages). lang and labels do not change which visible text a control shows.

Polish, ready to copy:

{
  "lang": "pl",
  "labels": {
    "video player": "odtwarzacz wideo",
    "Play": "Odtwórz",
    "Pause": "Pauza",
    "play": "odtwórz",
    "pause": "wstrzymaj",
    "Mute": "Wycisz",
    "Unmute": "Włącz dźwięk",
    "mute": "wycisz",
    "unmute": "włącz dźwięk",
    "seek": "przewijanie",
    "playback time": "czas odtwarzania",
    "{currentTime} of {totalTime}": "{currentTime} z {totalTime}",
    "{time} remaining": "pozostało: {time}",
    "video not loaded, unknown time.": "film niezaładowany, czas nieznany.",
    "hour": "godz.",
    "hours": "godz.",
    "minute": "min",
    "minutes": "min",
    "second": "s",
    "seconds": "s",
    "chapter: {chapterName}": "rozdział: {chapterName}",
    "Enter fullscreen mode": "Pełny ekran",
    "Exit fullscreen mode": "Zamknij pełny ekran",
    "enter fullscreen mode": "włącz pełny ekran",
    "exit fullscreen mode": "wyłącz pełny ekran",
    "Network Error": "Błąd sieci",
    "Decode Error": "Błąd dekodowania",
    "Source Not Supported": "Nieobsługiwane źródło",
    "Encryption Error": "Błąd szyfrowania",
    "A network error caused the media download to fail.": "Błąd sieci przerwał pobieranie filmu.",
    "A media error caused playback to be aborted. The media could be corrupt or your browser does not support this format.": "Odtwarzanie przerwane. Plik może być uszkodzony albo przeglądarka nie obsługuje tego formatu.",
    "An unsupported error occurred. The server or network failed, or your browser does not support this format.": "Nie udało się odtworzyć filmu. Zawiódł serwer lub sieć albo przeglądarka nie obsługuje tego formatu.",
    "The media is encrypted and there are no keys to decrypt it.": "Film jest zaszyfrowany i brakuje klucza."
  }
}

Fullscreen

The fullscreen button makes the whole <player-stack> fullscreen, so everything mounted inside it (watermark, action bar, end card, email gate, intro card, your own plugin overlays on ctx.container) stays visible. Elements placed outside the player, such as the chapters list and the yt-subscribe bar, are not shown. Page CSS for fullscreen should target player-stack:fullscreen (not media-controller:fullscreen); decorations set on player-stack, such as border-radius, also apply there unless you reset them.

Where the browser has no element fullscreen (iPhones that offer it only for video) or rejects the request, the same button, and requestFullscreen() on <player-stack>, opens the video’s own native fullscreen. That mode hides every HTML overlay, so overlays are visible there only while the video plays inline. If the video has not loaded yet, the click starts it and fullscreen opens once its metadata arrives. YouTube, Vimeo and Twitch embeds have no such mode, so the button is hidden for them there. Safari on iOS 26.5 does make the whole player fullscreen, overlays included (measured in the iOS Simulator).

PluginRegistry

Lower-level — you usually don’t need this directly. The Playerstack singleton uses it internally. Exposed in case you’re writing tooling.

import { createPluginRegistry } from "@playerstack/core";

const reg = createPluginRegistry();
reg.register(plugin);
await reg.init(ctx);
// ...
reg.destroy();

reg.init(ctx) throws if called twice without destroy() in between. A plugin whose init() throws or rejects does not stop the plugins after it: the registry logs the error, dispatches a bubbling playerstack:error event on ctx.container with detail: { reason: "plugin-init", plugin, error }, and reg.init(ctx) resolves to false (true when every plugin started).