Skip to main content
Version: 1.2.0

Viewing State & Events

Every io.video.videokit.live.viewer.StreamViewer implementation keeps its internal state and offers a way to register listener objects to listen to important events.

Viewer state#

The stream viewer state can be retrieved with StreamViewer.state and, similar to our other SDKs, it matches one of the constants in the io.video.videokit.live.viewer.StreamViewerState class:

StateDescription
StreamViewerState.IDLEViewer is ready to accept streams through StreamViewer.set. No stream was set.
StreamViewerState.BUFFERINGStream was set and will play as soon as buffering is finished.
StreamViewerState.WATCHINGStream was set and it is being played.
StreamViewerState.PAUSEDStream was set but playback was paused with pause(). Viewer is ready to play it as soon as play() is called.
StreamViewerState.PAUSED_BUFFERINGStream was set but playback was paused with pause(). Viewer is not ready to play because it needs to buffer more data.

Viewer events#

All StreamViewer events are dispatched to a io.video.videokit.live.viewer.StreamViewerListener that was previously registered using addListener.

streamViewer.addListener(lifecycle, listener) // start listening, stops automatically
streamViewer.addListener(listener) // start listening
streamViewer.removeListener(listener) // stop listening

Listeners are very important to be up-to-date about the stream viewer state, handle errors and create a responsive UI. We describe the listener interface as comments in the interface description below.

val streamViewer: StreamViewer = ...
streamViewer.addListener(object : StreamViewerListener {
override fun onError(error: VideoError) {
// Handle error!
}
override fun onStateChanged(@StreamViewerState.Value state: Int) {
// State has changed.
}
override fun onStreamChanged(stream: Stream?) {
// Stream has changed. This is called after set / reset, but also when the source
// stream is modified by the broadcaster. For example, if broadcaster pauses the stream,
// the stream object here will have stream.state == "paused".
}
override fun onMuteChanged(mute: Boolean) {
// Mute value was changed via StreamViewer.mute setter.
}
override fun onAspectModeChanged(@AspectMode.Value mode: Int) {
// Aspect mode was changed via StreamViewer.aspectMode setter.
}
})
Last updated on