Skip to main content
Version: Android SDK v1.2.1

Hosting Concepts

Hosting live streams means interacting with the io.video.videokit.live.host.StreamHost interface. This interface provides functions to:

  • start, pause and stop the streaming
  • control the camera through StreamHost.camera
  • listen to relevant events for building responsive UIs

The stream host 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 streamHost: StreamHost = ...
streamHost.addListener(object : StreamHostListener {
override fun onStreamChanged(stream: Stream) {
// New stream was created! Share with viewers.
}

override fun onError(error: VideoError) {
// Handle error!
}

override fun onResult(stream: Stream) {
// Called after confirm(). Stream is now marked as finished.
}
})

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. All of them will also automatically request the appropriate permissions (camera and microphone).

StreamHost interface

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

Start or pause streaming

To start streaming, temporarily pause or toggle between the two, you can use start / pause / toggle:

// start streaming, or resume previously paused stream
streamHost.start()

// pause streaming or toggle
streamHost.pause()
streamHost.toggle()

Confirm streaming

To stop streaming, marking the underlying Stream as finished, use confirm(). This will trigger StreamHostListener.onResult() which you can use to complete the user flow.

streamHost.confirm()

After confirming, the underlying Stream will be refreshed in case you plan to use the host again in a new stream.

Share the stream with viewers

At any moment, you can retrieve the current stream with the streamHost.stream property. We recommend, however, using the listener callback StreamHostListener.onStreamChanged(Stream), because the stream is created asynchronously, at start up and after every confirmation.

Control camera and streaming mode

To control the camera, please check out the documentation about the Camera object, which you can retrieve through StreamHost.camera, just like you do in the recorder SDK.

On top of this, the stream host offers three different streaming modes, which should be self explanatory.

streamHost.streamingMode = StreamingMode.CAMERA_AND_AUDIO
streamHost.streamingMode = StreamingMode.AUDIO_ONLY
streamHost.streamingMode = StreamingMode.CAMERA_ONLY