实现 Co-Watching API

。 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 标识名进行更新 在这些情况下的播放位置。

您可以使用以下方法控制“一起看”状态: