Quick Start
Updated: 2026-02-06 15:18:49
1. Core Concepts
1.1 PlaybackTarget
The playback target object contains all information about the playback video:
interface PlaybackTarget {
playbackId: string; // 回放唯一标识
title: string; // 回放标题
duration: number; // 回放时长(毫秒)
startTime?: number; // 开始时间
firstImage?: string; // 首帧图片
playbackOptions: SetupPlayerPlaybackOptions; // 播放器回放参数
chatReplayEnabled: boolean; // 聊天重放
chatMsgReplayEnabled: boolean; // 聊天消息重放
cardPushEnabled: boolean; // 卡片推送重放
// ... 其他重放功能
}
1.2 PlaybackType
Playback type enumeration:
| Type | Description |
|---|---|
PlaybackType.Record |
Temporary playback |
PlaybackType.Playback |
Normal playback |
PlaybackType.Vod |
VOD playback |
PlaybackType.Material |
Material library playback |
1.3 PlaybackMode
Playback mode enumeration:
| Type | Description |
|---|---|
PlaybackMode.Single |
Single playback |
PlaybackMode.List |
List playback |
2. Quick Start
2.1 Basic Flow
import { createWatchCore, PlaybackMode } from "@polyv/live-watch-sdk";
// 1. 初始化 WatchCore
const watchCore = createWatchCore({
// 配置参数
});
// 2. 安装 WatchCore
await watchCore.setup();
// 3. 获取回放方式(单个或列表)
const playbackMode = watchCore.playback.getCurrentPlaybackMode();
console.log("回放方式:", playbackMode);
if (playbackMode === PlaybackMode.Single) {
// 单个回放模式:直接获取单个回放对象
const playbackTarget = watchCore.playback.getSinglePlaybackTarget();
if (playbackTarget) {
// 设置当前回放对象到 SDK
watchCore.playback.setCurrentPlaybackTarget(playbackTarget);
// 创建播放器时传入回放选项
watchCore.player.setupPlayer({
container: document.getElementById("player"),
playbackOptions: playbackTarget.playbackOptions,
});
}
} else {
// 列表回放模式:获取回放列表
const playbackList = await watchCore.playback.getPlaybackList({
pageNumber: 1,
pageSize: 10,
});
console.log("回放总数:", playbackList.totalElements);
// 选择第一个回放进行播放
if (playbackList.contents.length > 0) {
const firstPlayback = playbackList.contents[0];
watchCore.playback.setCurrentPlaybackTarget(firstPlayback);
await watchCore.player.setupPlayer({
container: document.getElementById("player"),
playbackOptions: firstPlayback.playbackOptions,
});
}
}
2.2 Get a Specific Playback Video
import { PlaybackEvents } from "@polyv/live-watch-sdk";
// ...默认已处理 watchCore 相关逻辑
// 获取指定回放视频
const playbackTarget = await watchCore.playback.getPlaybackTargetById({
playbackId: "xxx",
});
watchCore.playback.setCurrentPlaybackTarget(playbackTarget);
// 创建播放器时传入回放选项
await watchCore.player.setupPlayer({
container: document.getElementById("player"),
playbackOptions: playbackTarget.playbackOptions,
});
// 切换回放
// await watchCore.player.changePlayback(playbackTarget.playbackOptions);
