CoWatchingHandler

@PublicApi
public interface CoWatchingHandler



Callbacks provided by the add-on app to handle remote co-watching updates and to query the state of the local media.

Summary

Public methods

abstract void

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

abstract Optional<QueriedCoWatchingState>

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

Public methods

onCoWatchingStateChanged

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
CoWatchingState state

the new CoWatchingState to be applied to the player

onStateQuery

abstract Optional<QueriedCoWatchingStateonStateQuery()

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:

QueriedCoWatchingState myCurrentPlaybackState = QueriedCoWatchingState
    .of(/* mediaPlayoutPosition= *{/} this.videoPlayer.videoTimestamp);
return Optional.of(myCurrentPlaybackState);
Returns
Optional<QueriedCoWatchingState>

Optional of QueriedCoWatchingState describing the current co-watching state. Empty Optional represents there is no co-watching activity in progress.