bccm-video-player
v3.5.1
Published
HLS video player built on Video.js v10. Custom skin with a settings menu (quality / audio / subtitles / speed), chapter markers, live mode, NPAW analytics, Chromecast and AirPlay.
Keywords
Readme
bccm-video-player
HLS video player built on Video.js v10. Custom skin with a settings menu (quality / audio / subtitles / speed), chapter markers, live mode, NPAW analytics, Chromecast and AirPlay.
Install
pnpm add bccm-video-playerimport { createPlayer } from "bccm-video-player"
import "bccm-video-player/css"Quick start
<div id="player"></div>const player = await createPlayer("player", {
src: { src: "https://example.com/stream.m3u8" },
autoplay: false,
languagePreferenceDefaults: { audio: "eng", subtitles: "eng" },
})Options
createPlayer(containerId, options)| Option | Type | Notes |
| -------------------------------------- | ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| src.src | string | HLS manifest URL. DASH is not supported — the player builds an <hlsjs-video>. |
| videoLanguages | VideoLanguageOption[] | Alternate renditions that differ in the picture itself — burned-in translated text, or a sign-language version. { language, src, label? }, language: null for the original. The selected entry supplies the source, so src.src is unused when this is set. |
| videoLanguage | string \| null | Which of videoLanguages to start on; unknown or absent falls back to the first entry. |
| autoplay | boolean | |
| live | boolean | Switches to the live skin: LIVE badge, no seek buttons / time displays / thumbnails. |
| language | string | UI language for tooltips, pickers, and error messages. Built-in: "en", "no", "nl", "de" (default "en"). Unsupported codes fall back to "en". Swap at runtime with player.setLanguage(...). See Adding a language. |
| languagePreferenceDefaults.audio | string | 3-letter code, e.g. "eng". |
| languagePreferenceDefaults.subtitles | string | 3-letter code, or omit to disable. |
| subtitles | Track[] | External <track> descriptors (src, srclang, label, kind). |
| chapters | Chapter[] | { start, duration, title, image? } in seconds. Renders segment markers on the progress bar and the chapter title while scrubbing; image doubles as the scrub preview still. |
| videojs.poster | string | Poster image URL. |
| videojs.crossOrigin | string | Defaults to "anonymous". |
| npaw | NPAWOptions | See Analytics. |
| onProgress | (currentTime, duration, player) => void | Fires on timeupdate. |
Player API
interface Player {
element: HTMLElement // <video-player> root
mediaEl: HTMLVideoElement // underlying <hlsjs-video> (use for play/pause/volume/events)
getAudioLanguages(): TrackOption[]
getSubtitleLanguages(): TrackOption[]
setAudioTrackToLanguage(language?: string): void
setSubtitleTrackToLanguage(language?: string): void
setVideoQuality(height: number): void // 0 / negative re-enables Auto (ABR)
getVideoLanguages(): VideoLanguageOption[]
getVideoLanguage(): string | null // null = the original version
setVideoLanguage(language: string | null): void
setLanguage(lang: string): void // swaps UI strings live; unsupported codes fall back to "en"
dispose(): void
}Video language
Some episodes ship more than one video rendition: the text burned into the picture is translated, or the whole thing is a sign-language version. These are separate manifests, not tracks inside one, so switching swaps the source.
Pass the renditions and the player grows a Video text language row in the settings menu as soon as there are two or more:
await createPlayer("player", {
videoLanguages: [
{ language: null, src: "https://.../original.m3u8" },
{ language: "nor", src: "https://.../nor.m3u8" },
],
videoLanguage: "nor", // optional; defaults to the first entry
})Switching keeps the playback position, the play/pause state, and the selected audio and subtitle languages. The engine survives the swap, so the persisted bandwidth estimate and the NPAW view carry over rather than restarting.
Codes are matched across spellings, so you can pass whatever your own language
picker holds: "nor", "nb" and "no" all find the same rendition, as do
"deu", "ger" and "de". A language the episode doesn't have falls back to
the original, which makes videoLanguage safe to set from the viewer's
language unconditionally:
await factory.create("player", { episodeId, videoLanguage: userLanguage })player.element fires bccm-videolanguagechange with
detail.language (the new code, or null) — useful for mirroring the choice
into a URL:
import { VIDEO_LANGUAGE_CHANGE_EVENT } from "bccm-video-player"
player.element.addEventListener(VIDEO_LANGUAGE_CHANGE_EVENT, (e) => {
console.log(e.detail.language)
})PlayerFactory fills videoLanguages in from the episode's streams, so BTV
callers get the picker for free and only pass the starting language.
For low-level control (play / pause / volume / events), use player.mediaEl:
player.mediaEl.play()
player.mediaEl.volume = 0.5
player.mediaEl.addEventListener("play", () => {
/* ... */
})Theming
The skin reads CSS variables from the player container.
| Variable | Default | Effect |
| ---------------------- | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| --bccm-color-primary | oklch(1 0 0) (white) | Text / icon color across the whole skin. Cascades via currentColor to slider fill, focus ring, hover backgrounds, live-badge accent. |
| --bccm-color-accent | oklch(1 0 0) (white) | Background of primary-action buttons (e.g. the OK on the error dialog). Foreground text auto-flips black/white based on lightness. |
| --bccm-font-family | Inter, system-ui | Font stack for all skin text (controls, tooltips, menus, error dialog, native captions). Load the webfont yourself. |
In fullscreen the skin scales itself up at 1280 / 1536 / 1920px viewport widths via an internal --bccm-scale. Any CSS added to the skin should be a --bccm-space multiple or multiplied by var(--bccm-scale), or it won't grow with the rest.
Set on the container:
<div
id="player"
style="--bccm-color-accent: #6EB0E6; --bccm-font-family: 'Archivo', sans-serif"
></div>Adding a language
Create
src/video-player/i18n/locales/<code>.ts:import type { LocaleTable } from "../strings" const de: LocaleTable = { seekBackward: "{seconds} Sekunden zurück", seekForward: "{seconds} Sekunden vor", // ... TypeScript will fail until every key in LocaleTable is filled in. } export default deRegister it in
src/video-player/i18n/strings.ts— three lines: animport, an entry inSUPPORTED_LANGS, and an entry inSTRINGS.Add the matching BCP 47 tag to
CORE_LOCALEinsrc/video-player/i18n/core-i18n.ts. This picks which of Video.js core's shipped locale packs to use for its built-in components, with our wording overlaid on top. Note core has nonopack — Norwegian maps tonb.
Record<Lang, ...> in both files makes it a compile error if any step is missed.
en.ts is the canonical reference for which keys exist and how interpolation placeholders (e.g. {seconds}, {height}, {label}) are spelled.
Keyboard
The settings menu uses Video.js core's menu behaviour:
↑ / ↓— move between items, wrappingHome / End— first / last itemEnter / Space— select, or open a submenuEsc— close the menu- Typing a letter jumps to the next matching item
Analytics (NPAW)
createPlayer("player", {
src: { src: "..." },
npaw: {
enabled: true,
accountCode: "...",
appName: "web",
tracking: {
isLive: false,
userId: "...",
sessionId: "...",
metadata: {
contentId: "E385",
title: "...",
showTitle: "...",
},
},
},
})Adds ~800 KB to the bundle. Omit npaw (or set enabled: false) to skip.
BTV factory (internal)
For BCC apps that resolve streams from the BTV API:
import { PlayerFactory } from "bccm-video-player"
const factory = new PlayerFactory({
tokenFactory: null,
endpoint: "https://api.brunstad.tv/query",
})
await factory.create("player", { episodeId: "865" })
// Start on a specific video language; the rest stay available in the menu.
await factory.create("player", { episodeId: "865", videoLanguage: "nor" })It picks one stream per video language — hls_cmaf ahead of hls_ts, DASH
skipped — and returns null when the episode has no playable HLS stream.
Development
pnpm i
pnpm dev # demo at http://localhost:5173
pnpm test # vitest
pnpm build # tsc + vite + d.tsPublishing
Bump version in package.json, then:
pnpm publish