Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Co-Watching API quản lý trải nghiệm họp của nhiều người tham gia xem hoặc nghe nội dung trong ứng dụng của bạn.
Hướng dẫn này giải thích cách triển khai Co-Watching API.
Bắt đầu
Để sử dụng Co-Watching API, trước tiên, bạn phải Triển khai một tiện ích bổ sung Meet. Sau khi hoàn tất các bước đó, bạn có thể bắt đầu sử dụng API Cùng xem trong tiện ích bổ sung mới.
Để sử dụng Co-Watching API, hãy bắt đầu bằng cách lấy một đối tượng AddonSession. Đối tượng này đóng vai trò là điểm truy cập cho các hoạt động cùng nhau trong Google Meet:
CoWatchingDelegate là cách Co-Watching API cập nhật ứng dụng của bạn bất cứ khi nào có trạng thái mới. Dự kiến là khi phương thức onCoWatchingStateChanged() được gọi, ứng dụng của bạn sẽ áp dụng ngay trạng thái mới.
Mã mẫu sau đây cho biết cách sử dụng Co-Watching API:
TypeScript
constcoWatchingClient=awaitaddonSession.createCoWatchingClient({activityTitle:"ACTIVITY_TITLE",onCoWatchingStateQuery(){// This function should return the current state of your CoWatching activityreturngetMyApplicationCoWatchingState();},onCoWatchingStateChanged(coWatchingState:CoWatchingState){// This function should apply newState to your ongoing CoWatching activity},});
Thay thế ACTIVITY_TITLE bằng tiêu đề nội dung nghe nhìn của hoạt động.
Quản lý trạng thái hiện tại
Khi người dùng thực hiện hành động trong ứng dụng của bạn, ứng dụng của bạn dự kiến sẽ gọi ngay các phương thức API được cung cấp.
Bạn chỉ nên gọi các phương thức này để phản hồi các sự kiện quan trọng. Ví dụ: bạn không cần gọi các phương thức này mỗi khi ứng dụng của bạn chuyển sang một video đang phát. CoWatchingDelegate mà bạn tạo sẽ xử lý việc nhận các vị trí phát được cập nhật trong những trường hợp này.
Bạn có thể kiểm soát trạng thái cùng xem bằng các phương thức sau:
notifyBuffering(): Gọi khi ứng dụng của người dùng bắt đầu lưu vào bộ nhớ đệm do lưu vào bộ nhớ đệm từ một lần chuyển đổi nội dung nghe nhìn trước đó, thao tác tìm kiếm nội dung nghe nhìn hoặc tình trạng tắc nghẽn mạng.
notifyPauseState():
Gọi khi người dùng tạm dừng hoặc tiếp tục phát nội dung nghe nhìn.
notifyPlayoutRate():
Gọi khi người dùng cập nhật tốc độ phát thành một giá trị mới (ví dụ: 1,25x).
notifyReady(): Gọi khi quá trình đệm hoàn tất và nội dung nghe nhìn hiện đã sẵn sàng phát.
notifySwitchToMedia(): Gọi bất cứ khi nào nội dung nghe nhìn đang phát thay đổi. Ví dụ: người dùng chọn một video mới hoặc tính năng tự động phát bắt đầu video tiếp theo.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-29 UTC."],[],[],null,["# Implement the Co-Watching API\n\n| **Early Access Program:** This feature was only available in limited preview, through an Early Access Program. This program is now closed to new signups.\n\nThe Co-Watching API manages the meeting experience of multiple\nparticipants watching or listening to content in your app.\n\nThis guide explains how to implement the Co-Watching API.\n\nGet started\n-----------\n\nTo use the Co-Watching API, you first must [Deploy a\nMeet add-on](/workspace/meet/add-ons/guides/deploy-add-on). Once\nyou've completed those steps, you can start using the Co-Watching API\nfrom within your new add-on.\n\nTo use the Co-Watching API, start by getting an\n[`AddonSession`](/workspace/meet/add-ons/reference/websdk/addon_sdk.addonsession) object,\nwhich serves as the entry point for Google Meet co-activities: \n\n### TypeScript\n\n const session = await window.meet.addon.createAddonSession({\n cloudProjectNumber: \"\u003cvar translate=\"no\"\u003eCLOUD_PROJECT_NUMBER\u003c/var\u003e\",\n });\n\nReplace \u003cvar translate=\"no\"\u003eCLOUD_PROJECT_NUMBER\u003c/var\u003e with the project number of\nyour Google Cloud project.\n\nCreate a co-watching client\n---------------------------\n\nTo get started, create a\n[`CoWatchingClient`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingclient)\nobject from your `AddonSession`.\n\nTo create a `CoWatchingCient`, call the\n[`createCoWatchingClient()`](/workspace/meet/add-ons/reference/websdk/addon_sdk.addonsession.createcowatchingclient)\nmethod and provide a\n[`CoWatchingDelegate`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingdelegate)\nobject.\n\nThe `CoWatchingDelegate` is how the Co-Watching API updates your app\nwhenever it has a new state available. It's expected that, when the\n[`onCoWatchingStateChanged()`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingdelegate.oncowatchingstatechanged)\nmethod is called, your app immediately applies the new state.\n\nThe following code sample shows how to use the Co-Watching API: \n\n### TypeScript\n\n const coWatchingClient = await addonSession.createCoWatchingClient({\n activityTitle: \"\u003cvar translate=\"no\"\u003eACTIVITY_TITLE\u003c/var\u003e\",\n onCoWatchingStateQuery() {\n // This function should return the current state of your CoWatching activity\n return getMyApplicationCoWatchingState();\n },\n onCoWatchingStateChanged(coWatchingState: CoWatchingState) {\n // This function should apply newState to your ongoing CoWatching activity\n },\n });\n\nReplace \u003cvar translate=\"no\"\u003eACTIVITY_TITLE\u003c/var\u003e with your activity's media title.\n\nManage current state\n--------------------\n\nWhen users take action in your application, it's expected that your application\nimmediately calls the provided API methods.\n\nYou should only call these methods in response to significant events. For\nexample, you don't need to call them every time your app advances a playing\nvideo. The `CoWatchingDelegate` you create handles getting updated playout\npositions in these circumstances.\n\nYou can control the co-watching state using these methods:\n\n- [`notifyBuffering()`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingclient.notifybuffering):\n Call when a user's app starts buffering due to buffering from a prior media\n switch, media seek, or network congestion.\n\n- [`notifyPauseState()`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingclient.notifypausestate):\n Call when a user pauses or unpauses the playing media.\n\n- [`notifyPlayoutRate()`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingclient.notifyplayoutrate):\n Call when a user updates the playback speed to a new value (for example,\n 1.25x).\n\n- [`notifyReady()`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingclient.notifyready):\n Call when buffering completes and the media is now ready to be played.\n\n- [`notifySeekToTimestamp()`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingclient.notifyseektotimestamp):\n Call when a user explicitly changes the play out position.\n\n- [`notifySwitchToMedia()`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingclient.notifyswitchedtomedia):\n Call whenever the actively playing media changes. For example, the user\n selects a new video, or autoplay starts the next video."]]