@broadcastingplatforms/player

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

用 Lit 构建的通用视频播放器网络组件

中文使用文档
文档目录17 节
  1. 安装
  2. 独立对非独立
  3. 独立套装
  4. 非单体( 邦德勒 )
  5. 基本用途
  6. HLS 视频 (大巴克兔子)
  7. 平流线
  8. BPLive 剪贴板
  9. 带有默认 UI
  10. 程序控制
  11. 属性
  12. 来源描述
  13. 玩家来源类型
  14. 提供者配置
  15. 分析
  16. 活动
  17. 自定义视频元素

@ 广播平台/ 播放器

通用视频播放器网络组件由Lit. Supports HLS,WebRTC(通过纳米斯特雷姆)和LiveKit所建.

安装

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

独立对非独立

独立套装

需要所有依赖性(HLS.js等)捆绑的单个文件时使用独立捆绑. CDN使用理想或简单的HTML页面.

<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>

非单体( 邦德勒 )

使用捆绑时使用标准导入( Vite, webpack等) 。 依附有外生而有树相起.

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

基本用途

HLS 视频 (大巴克兔子)

<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 平台的直播流 :

<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 剪贴板

从 BPLive 平台播放剪辑 :

<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>

带有默认 UI

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

程序控制

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);
});

属性

属性可以被设定为JSON字符串或JavaScript属性.

属性类型说明
sourceSourceDescription (杰森语)源描述为 sources 数组和可选 poster
configProviderConfig (杰森语)提供者配置( HLS, NanoPlayer, LiveKit, BPLive)
autoplayboolean自动启动播放
mutedboolean开始哑声
loopboolean回放循环

来源描述

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

玩家来源类型

// 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'
}

提供者配置

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
}

分析

通过 ready 使用 @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>

活动

活动细节说明
readyPlayerCore玩家准备好了就被解雇了
play- 说吧播放开始
pause- 说吧播放暂停
ended- 说吧播放结束
timeupdate- 说吧当前更新时间
error- 说吧回放出错

自定义视频元素

对于高级使用案例,您可以直接使用自定义视频元素:

import { HlsVideoElement, NanoVideoElement, LiveKitVideoElement } from '@broadcastingplatforms/player/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 是什么?

用 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 和提交记录判断。