CoWatchingHandler

@PublicApi
public interface CoWatchingHandler



插件应用提供的回调,用于处理远程同看更新以及查询本地媒体的状态。

摘要

公共方法

abstract void

应用会议中其他参与者的“一起看”状态更新。

abstract Optional<QueriedCoWatchingState>

检索本地“一起看”活动的当前状态。

公共方法

onCoWatchingStateChanged

abstract void onCoWatchingStateChanged(CoWatchingState state)

应用会议中其他参与者的“一起看”状态更新。

注意:系统不会为响应本地更改而调用此方法。

实现示例:

// 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();
}
参数
CoWatchingState state

要应用于播放器的新 CoWatchingState

onStateQuery

abstract Optional<QueriedCoWatchingStateonStateQuery()

检索本地“一起看”活动的当前状态。

此函数将定期调用,因此在写入时应保证性能出色(例如 <100ms)。

实现示例:

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

QueriedCoWatchingStateOptional,用于描述当前的“一起看”状态。Optional 为空表示没有正在进行的一起看活动。