Skip to main content
Version: Android SDK v1.2.0

Viewing Concepts

Viewing live streams means interacting with the io.video.videokit.live.viewer.StreamViewer interface. This interface provides functions to:

  • choose the Stream that should be played
  • play, pause and stop the stream
  • control playback (e.g. StreamViewer.mute, StreamViewer.aspectMode)
  • listen to relevant events for building responsive UIs

The stream viewer will forward all relevant events to subscribers that were registered with the addListener* functions. We recommend listening at least to the error and stream events:

val streamViewer: StreamViewer = ...
streamViewer.addListener(object : StreamViewerListener {
override fun onError(error: VideoError) {
// Handle error!
}
})

We provide different implementations that can be used within your app depending on your needs, but all of them share the same API surface described below.

StreamViewer interface

Note: if you use the default controls, the user will be able to control the viewer through the user interface, so there's no need to interact directly with these functions.

Playback control

Playback is controlled through simple play and pause functions.

streamViewer.play() // Start or resume playing the current stream
streamViewer.pause() // Pause playing current stream
streamViewer.toggle() // Play if paused, pause if playing

Stream control

Similarly to the player module, the stream viewer accepts input data through the set() function, which lets you choose whether the content should be played right away or just preloaded. To clear the current stream, call reset().

streamViewer.set(stream, play = true) // Load and play
streamViewer.set(stream, play = false) // Just load

streamViewer.reset() // Stop playback and clear content

At any moment, the current stream can be retrieved using StreamViewer.stream. Changes in this property will also trigger the onStreamChanged() callback.

Other options

We also offer a few extra options that can be used to configure the player:

  • aspectMode: either AspectMode.FILL, AspectMode.CENTER_CROP or AspectMode.CENTER_INSIDE.
  • mute: whether the audio is muted or not.
streamViewer.aspectMode = AspectMode.CENTER_CROP // crop exceeding dimension after scaling
streamViewer.aspectMode = AspectMode.FILL // fill the viewport. Image might be distorted
streamViewer.aspectMode = AspectMode.CENTER_INSIDE // fill the viewport but respect scale

streamViewer.mute = true // mute audio
streamViewer.mute = false // don't mute audio