Mantieni tutto organizzato con le raccolte Salva e classifica i contenuti in base alle tue preferenze.
L'API Co-Watching gestisce l'esperienza di riunione di più partecipanti che guardano o ascoltano contenuti nella tua app.
Questa guida spiega come implementare l'API Co-Watching.
Inizia
Per utilizzare l'API Guarda insieme, devi prima implementare un componente aggiuntivo di Meet. Una volta completati questi passaggi, puoi iniziare a utilizzare l'API Co-Watching dal nuovo componente aggiuntivo.
Per utilizzare l'API Co-Watching, inizia recuperando un oggetto AddonSession, che funge da punto di accesso per le co-attività di Google Meet:
L'CoWatchingDelegate è il modo in cui l'API Co-Watching aggiorna la tua app ogni volta che è disponibile un nuovo stato. Quando viene chiamato il metodo onCoWatchingStateChanged(), l'app applica immediatamente il nuovo stato.
Il seguente esempio di codice mostra come utilizzare l'API Co-Watching:
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},});
Sostituisci ACTIVITY_TITLE con il titolo del media della tua attività.
Gestire lo stato attuale
Quando gli utenti intraprendono un'azione nella tua applicazione, è previsto che l'applicazione chiami immediatamente i metodi API forniti.
Devi chiamare questi metodi solo in risposta a eventi significativi. Ad esempio, non è necessario chiamarli ogni volta che l'app avanza nella riproduzione di un video. Il CoWatchingDelegate che crei gestisce l'aggiornamento delle posizioni di riproduzione in queste circostanze.
Puoi controllare lo stato della visione condivisa utilizzando questi metodi:
notifyBuffering(): Chiamata quando l'app di un utente inizia il buffering a causa del buffering di un precedente cambio di contenuti multimediali, ricerca di contenuti multimediali o congestione della rete.
notifyPauseState(): Chiamata quando un utente mette in pausa o riprende la riproduzione dei contenuti multimediali.
notifyPlayoutRate(): Chiamata quando un utente aggiorna la velocità di riproduzione a un nuovo valore (ad esempio, 1,25x).
notifyReady(): Chiama quando il buffering è completato e i contenuti multimediali sono pronti per essere riprodotti.
notifySeekToTimestamp(): Chiamata quando un utente modifica esplicitamente la posizione di riproduzione.
notifySwitchToMedia(): Chiama ogni volta che cambiano i contenuti multimediali in riproduzione. Ad esempio, l'utente seleziona un nuovo video o la riproduzione automatica avvia il video successivo.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-08-04 UTC."],[],[],null,["| **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\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\nTypeScript \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\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\nTypeScript \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\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."]]