實作 Co-Watching API

Google Meet 即時分享共同觀看 API 可管理多位參與者在應用程式中觀看或聆聽內容的會議體驗。

本指南說明如何實作 Co-Watching API。

建立 CoWatchingClient

首先,請透過您在開始使用期間建立的 AddonSession 建立 createCoWatchingClient

如要建立 CoWatchingCient,請呼叫 AddonSession.createCoWatchingClient 方法並提供 CoWatchingDelegate

CoWatchingDelegate 是 Co-Watching API 如何在新狀態可用時更新應用程式。正常情況下,呼叫 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 替換成活動的媒體標題。

管理目前狀態

當使用者在應用程式中採取行動時,應用程式應能立即呼叫所提供的 API 方法。

您只能在回應重大事件時呼叫這些方法。舉例來說,您不需要在每次應用程式播放影片播放時呼叫呼叫端。在這些情況下,您在上方建立的 CoWatchingDelegate 會控制更新播放位置。

您可以使用下列方法控制共同觀看狀態: