Skip to main content
Version: Android SDK v1.2.0

Hosting State & Events

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

Host state

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

StateDescription
StreamHostState.BUSYThe host is asking the user for permissions, or asking the backend for a Stream object.
StreamHostState.IDLEThe host is not streaming, but it is ready to. Stream might have started and then paused, or never started.
StreamHostState.STREAMINGThe host is currently streaming, with good network speed conditions.
StreamHostState.BACKPRESSUREThe host should be streaming but network conditions are bad. In this state, recording is suspended until the upload queue becomes manageable again. This should be shown to the end user, because whatever happens in this state will not be streamed to viewers.

When the host is transitioning from one state to another (that is, state is StreamHostState.BUSY), you can check the state that is being transitioned to using StreamHost.targetState.

Host events

All StreamHost events are dispatched to a io.video.videokit.live.host.StreamHostListener that was previously registered using addListener.

streamHost.addListener(lifecycle, listener) // start listening, stops automatically

streamHost.addListener(listener) // start listening
streamHost.removeListener(listener) // stop listening

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

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.
}

override fun onStateChanged(@StreamHostState.Value state: Int) {
// State has changed.
}

override fun onDurationChanged(duration: Long) {
// Stream duration has changed. This is called repeatedly as
// streaming progresses.
}

override fun onStreamingModeChanged(@StreamingMode.Value streamingMode: Int) {
// Streaming mode was changed via StreamHost.streamingMode setter.
}
})