。 Google Meet 实时共享 Co-Watching API 可管理多位参与者的会议体验 观看或收听应用中的内容
本指南介绍了如何实现 Co-Watching API。
创建 CoWatchingClient
首先,请创建
createCoWatchingClient
来源:AddonSession
您在开始使用中创建的链接。
如需创建 CoWatchingCient
,请调用
AddonSession.createCoWatchingClient
方法,并提供
CoWatchingDelegate
。
Co-Watching API 通过CoWatchingDelegate
来更新您的
应用。预计
CoWatchingDelegate.onCoWatchingStateChanged
方法之后,您的应用会立即应用新状态。
以下代码示例展示了如何使用 Co-Watching API:
TypeScript
const coWatchingClient = await addonSession.createCoWatchingClient({
activityTitle: "ACTIVITY_TITLE",
onCoWatchingStateQuery() {
// This function should return the current state of your CoWatching activity
return getMyApplicationCoWatchingState();
},
onCoWatchingStateChanged(coWatchingState: CoWatchingState) {
// This function should apply newState to your ongoing CoWatching activity
},
});
将 ACTIVITY_TITLE 替换为您的 activity 的媒体标题。
管理当前状态
当用户在您的应用中执行操作时,应用应该 立即调用所提供的 API 方法。
您应仅在发生重要事件时调用这些方法。对于
例如,您无需在每次应用进入播放模式时都调用它们
视频。您在上面创建的 CoWatchingDelegate
标识名进行更新
在这些情况下的播放位置。
您可以使用以下方法控制“一起看”状态:
CoWatchingClient.notifySwitchToMedia
: 每当正在播放的媒体发生变化时调用。例如,用户 选择新视频或自动播放下一个视频。CoWatchingClient.notifyPauseState
: 在用户暂停或取消暂停正在播放的媒体时调用。CoWatchingClient.notifySeekToTimestamp
: 在用户明确改变播放位置时调用。CoWatchingClient.notifyPlayoutRate
: 在用户将播放速度更新为新值(例如, 1.25 倍)。CoWatchingClient.notifyBuffering
: 当用户的应用因从之前的媒体开始缓冲而开始缓冲时调用 切换、媒体跳转或网络拥塞。CoWatchingClient.notifyReady
: 在缓冲完成且媒体现在可供播放时调用。