The Google Meet Live Sharing SDK is in preview. Developers can apply for access through our Early Access Program.

CoWatchingSessionDelegate

Stay organized with collections Save and categorize content based on your preferences.
public interface CoWatchingSessionDelegate

Callbacks provided by the Live Sharing App to handle remote co-watching updates and to query the state of the local media.

Public Method Summary

abstract void
onCoWatchingStateChanged(CoWatchingState state)
Applies a co-watching state update from another participant in the meeting.
abstract Optional<CoWatchingState>
onCoWatchingStateQuery()
Retrieves the current state of the local co-watching activity.

Public Methods

public abstract void onCoWatchingStateChanged (CoWatchingState state)

Applies a co-watching state update from another participant in the meeting.

Note: This will not be called in response to local changes.

Implementation example:

// Handle transition to new video.
if (!newState.mediaId().equals(this.videoPlayer.videoUrl)) {
  this.videoPlayer.loadVideo(newState.mediaId());
}

// Only adjust the local video playout if it is sufficiently diverged from the timestamp in the
// applied update.
if (newState
        .mediaPlayoutPosition()
        .minus(this.videoPlayer.videoTimestamp)
        .compareTo(Duration.ofMillis(500))
    > 0) {
  this.videoPlayer.seek(newState.mediaPlayoutPosition());
}

// Update pause state if necessary.
if (newState.playbackState().equals(PLAY) && this.videoPlayer.isPaused) {
  this.videoPlayer.unpause();
} else if (newState.playbackState().equals(PAUSE) && !this.videoPlayer.isPaused) {
  this.videoPlayer.pause();
}
Parameters
state the new CoWatchingState to be applied to the player.

public abstract Optional<CoWatchingState> onCoWatchingStateQuery ()

Retrieves the current state of the local co-watching activity.

This will be called regularly so it should be written to be performant (e.g. <100ms).

Implementation example:

CoWatchingState myCurrentPlaybackState =
    CoWatchingState.builder()
        .setMediaId(this.videoPlayer.videoUrl)
        .setMediaPlayoutPosition(this.videoPlayer.videoTimestamp)
        .setPlaybackState(this.videoPlayer.isPaused ? PAUSE : PLAY)
        .setMediaPlayoutRate(1.0)
        .build();
return Optional.of(myCurrentPlaybackState);
Returns