Skip to main content
Version: Android SDK v1.3.0

Streams

Managing live streams happens through the stream store component that you can retrieve with VideoKit.streams(). Just like other network APIs, you will need a valid session to perform these operation successfully. All functions of this component are asynchronous and will return the usual Call object, described here.

Creating streams​

We recommend to let the stream host component create streams for you, but should you need to do it, you can do so as follows:

val streams: StreamStore = VideoKit.streams()
streams.create(StreamProfile.LowLatency).onSuccess {
// Got stream!
}.onError {
// Something went wrong
}

Coroutine users can use createSuspending too.

Fetching a stream​

To retrieve a stream by its id, simply use get:

val streams: StreamStore = VideoKit.streams()
streams.get("stream_id").onSuccess {
// Got stream!
}.onError {
// Something went wrong
}

Coroutine users can use getSuspending too.

You can also subscribe to stream changes using observe. It returns a Registration that you can listen to and be notified whenever the stream changes. This is especially useful for monitoring the stream state property.

val streams: StreamStore = VideoKit.streams()
val registration: Registration<Stream> = streams.observe("stream_id")
registration.addObserver(object : Registration.Observer<Stream> {
override fun onValueChanged(old: Stream?, new: Stream?) {
// Stream changed from old to new!
}
})

Deleting streams​

To delete a stream, all you need is its id:

val streams: StreamStore = VideoKit.streams()
streams.delete(stream.id).onSuccess {
// Deleted!
}.onError {
// Something went wrong
}

Coroutine users can use deleteSuspending too.

Querying streams​

To query for available streams, you can use the list API. The function accepts a request object which can be configured to filter streams by state. For example, to retrieve all streams that are in the live state:

val streams: StreamStore = VideoKit.streams()
streams.list(StreamRequest(state = "live")).onSuccess {
// Got streams!
}.onError {
// Something went wrong
}

Coroutine users can use listSuspending too.