The Google Meet Live Sharing Co-Watching API manages the meeting experience of multiple participants watching or listening to content in your app.
This guide explains how to implement the Co-Watching API.
Create a CoWatchingClient
To get started, create a
createCoWatchingClient
from the AddonSession
you created in Get started.
To create a CoWatchingCient
, call the
AddonSession.createCoWatchingClient
method and provide a
CoWatchingDelegate
.
The CoWatchingDelegate
is how the Co-Watching API updates your
application whenever it has a new state available. It's expected that, when the
CoWatchingDelegate.onCoWatchingStateChanged
method is called, your application will immediately apply the new state.
The following code sample shows how to use the 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
},
});
Replace ACTIVITY_TITLE with the media title of your activity.
Manage current state
When users take action in your application, it's expected that your application immediately calls the provided API methods.
You should only call these methods in response to significant events. For
example, you don't need to call them every time your app advances a playing
video. The CoWatchingDelegate
you created above handles getting updated
playout positions in these circumstances.
You can control the co-watching state using these methods:
CoWatchingClient.notifySwitchToMedia
: Call whenever the actively playing media changes. For example, the user selects a new video, or autoplay starts the next video.CoWatchingClient.notifyPauseState
: Call when a user pauses or unpauses the playing media.CoWatchingClient.notifySeekToTimestamp
: Call when a user explicitly changes the play out position.CoWatchingClient.notifyPlayoutRate
: Call when a user updates the playback speed to a new value (for example, 1.25x).CoWatchingClient.notifyBuffering
: Call when a user's app starts buffering due to buffering from a prior media switch, media seek, or network congestion.CoWatchingClient.notifyReady
: Call when buffering completes and the media is now ready to be played.