@broadcastingplatforms/player

中文文档
1.5.10发布于 2026/11/06SEE LICENSE IN LICENSETypeScriptES Module近 30 天下载 1724

Universal video player web component built with Lit

原始使用文档
文档目录17 节
  1. Installation
  2. Standalone vs Non-Standalone
  3. Standalone Bundle
  4. Non-Standalone (Bundler)
  5. Basic Usage
  6. HLS Video (Big Buck Bunny)
  7. BPLive Stream
  8. BPLive Clip
  9. With Default UI
  10. Programmatic Control
  11. Attributes
  12. SourceDescription
  13. PlayerSource Types
  14. ProviderConfig
  15. Analytics
  16. Events
  17. Custom Video Elements

@broadcastingplatforms/player

Universal video player web component built with Lit. Supports HLS, WebRTC (via nanoStream), and LiveKit.

Installation

npm install @broadcastingplatforms/player
# or
pnpm add @broadcastingplatforms/player

Standalone vs Non-Standalone

Standalone Bundle

Use the standalone bundle when you want a single file with all dependencies (HLS.js, etc.) bundled. Ideal for CDN usage or simple HTML pages.

<script type="module" src="https://unpkg.com/@broadcastingplatforms/player/dist/bp-player.standalone.mjs"></script>

<bp-player
  source='{"sources":[{"type":"video","url":"https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8"}]}'
  muted
  autoplay
></bp-player>

Non-Standalone (Bundler)

Use the standard import when using a bundler (Vite, webpack, etc.). Dependencies are external and tree-shakeable.

import '@broadcastingplatforms/player';
<bp-player
  source='{"sources":[{"type":"video","url":"https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8"}]}'
  muted
  autoplay
></bp-player>

Basic Usage

HLS Video (Big Buck Bunny)

<bp-player
  source='{"sources":[{"type":"video","url":"https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8"}],"poster":"https://peach.blender.org/wp-content/uploads/bbb-splash.png"}'
  muted
  autoplay
></bp-player>

BPLive Stream

Play a live stream from the BPLive platform:

<bp-player id="live-player" muted autoplay></bp-player>

<script type="module">
  const player = document.getElementById('live-player');

  player.source = { sources: [{ type: 'bplive', streamId: 123 }] };
  player.config = {
    bpLive: {
      discoveryUrl: 'https://api.example.com',
      authToken: await getAuthToken() // Set programmatically, not in HTML
    }
  };
</script>

BPLive Clip

Play a clip from the BPLive platform:

<bp-player id="clip-player" muted autoplay></bp-player>

<script type="module">
  const player = document.getElementById('clip-player');

  player.source = {
    sources: [{ type: 'bplive', clipId: 456, preferredOrientation: 'portrait' }]
  };
  player.config = {
    bpLive: {
      discoveryUrl: 'https://api.example.com',
      authToken: await getAuthToken() // Set programmatically, not in HTML
    }
  };
</script>

With Default UI

<bp-default-ui
  source='{"sources":[{"type":"video","url":"https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8"}]}'
></bp-default-ui>

Programmatic Control

import { BPPlayer, type SourceDescription } from '@broadcastingplatforms/player';

const player = document.querySelector('bp-player') as BPPlayer;

// Set source via property (object)
player.source = {
  sources: [{ type: 'video', url: 'https://example.com/stream.m3u8' }],
  poster: 'https://example.com/poster.jpg'
};

player.addEventListener('ready', (e) => {
  const core = e.detail; // PlayerCore instance
  
  core.play();
  core.pause();
  core.seek(30); // seek to 30 seconds
  core.setVolume(0.5);
  core.setMuted(true);
  
  // Access current state
  console.log(core.state.currentTime);
  console.log(core.state.duration);
  console.log(core.state.paused);
});

Attributes

Attributes can be set as JSON strings or as JavaScript properties.

AttributeTypeDescription
sourceSourceDescription (JSON)Source description with sources array and optional poster
configProviderConfig (JSON)Provider configuration (HLS, NanoPlayer, LiveKit, BPLive)
autoplaybooleanAuto-start playback
mutedbooleanStart muted
loopbooleanLoop playback

SourceDescription

interface SourceDescription {
  sources: PlayerSource[];
  poster?: string;
}

PlayerSource Types

// Standard video/HLS source
interface VideoSource {
  type: 'video';
  url: string;
}

// BPLive stream source
interface BPLiveStreamSource {
  type: 'bplive';
  streamId: number;
}

// BPLive clip source
interface BPLiveClipSource {
  type: 'bplive';
  clipId: number;
  preferredOrientation?: 'landscape' | 'portrait'; // defaults to 'landscape'
}

ProviderConfig

interface ProviderConfig {
  bpLive?: BPLiveConfig;
  // ... other provider configs
}

interface BPLiveConfig {
  discoveryUrl: string;  // Base URL of the BPLive API (required)
  authToken?: string;    // Bearer token for authenticated API requests
}

Analytics

Connect analytics via the ready event using @broadcastingplatforms/web-connectors:

<bp-player
  id="player"
  source='{"sources":[{"type":"video","url":"..."}]}'
></bp-player>

<script type="module">
  import { createMuxConnector } from '@broadcastingplatforms/web-connectors/mux';

  document.getElementById('player').addEventListener('ready', (e) => {
    // Auto-destroys when player is destroyed
    createMuxConnector(e.detail, {
      envKey: 'your-mux-env-key',
      data: { video_title: 'My Video' }
    });
  });
</script>

Events

EventDetailDescription
readyPlayerCoreFired when player is ready
play-Playback started
pause-Playback paused
ended-Playback ended
timeupdate-Current time updated
error-Playback error occurred

Custom Video Elements

For advanced use cases, you can use the custom video elements directly:

import { HlsVideoElement, NanoVideoElement, LiveKitVideoElement } from '@broadcastingplatforms/player/elements';

These are media-chrome compatible custom elements.

版本与发布记录

@broadcastingplatforms/player 共发布 35 个版本,首次发布于 2026/01/14;过去 12 个月发布了 35 个版本。

版本发布日期距今
1.5.10latest2026/11/063 天前
1.5.92026/11/045 天前
1.5.82026/11/027 天前
1.5.72026/10/3010 天前
1.5.22026/10/2219 天前
1.5.12026/10/2020 天前

其他发布通道:dev → 0.0.0-dev.e67afbe。

关于 @broadcastingplatforms/player 的常见问题

@broadcastingplatforms/player 是什么?

Universal video player web component built with Lit

如何安装 @broadcastingplatforms/player?

在项目目录运行 npm install @broadcastingplatforms/player,或使用 pnpm add / yarn add / bun add。

@broadcastingplatforms/player 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@broadcastingplatforms/player 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@broadcastingplatforms/player 可以商用吗?

@broadcastingplatforms/player 使用 SEE LICENSE IN LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@broadcastingplatforms/player 的下载量有多少?

根据 npm 官方下载统计,@broadcastingplatforms/player 在 2026/10/09 – 2026/11/07 这 30 天内被下载 1,724 次,日均约 57 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@broadcastingplatforms/player 还在维护吗?

最新版本 1.5.10 发布于 2026/11/06(3 天前);至今共发布 35 个版本,其中过去 12 个月发布了 35 个;首次发布于 2026/01/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。