Hosting live streams means interacting with the
This interface provides functions to:
- start, pause and stop the streaming
- control the camera through
- listen to relevant events through
addListener(StreamHostListener), useful for building responsive UIs
We provide three
StreamHost implementations that you can choose from depending on your case.
The usage varies a bit but they all share the same functionality from
StreamHostController is the low level implementation that, unlike the others, is detached from
the UI. You will typically hold the controller instance in a ViewModel. Optionally,
for perfect state restoration during configuration changes, we also recommend that you use Android's
and pass it to the controller constructor.
As you can see, the
StreamHostController must be released when you're done with it.
In order to show the UI and start using the host, you must also call one of the
as soon as you have a view container. For example, with a fragment:
By passing in the fragment instance, the controller will know how to ask for permissions. We also use the fragment lifecycle to avoid memory leaks, so there's no need to unbind.
StreamHostFragment is a fragment implemented exactly as described above. It is
the recommended implementation as it is very easy to use - no need to release or bind UI,
because the fragment owns the views.
You can customize the fragment after it is attached or when creating it, thanks to
StreamHostView is a view that holds a controller, to be used for codebases that
do not use fragments at all. Just like the controller:
- The view must be released with
- You must pass a fragment / activity / lifecycle with
Once you have chosen the stream host implementation, using it is pretty simple.
At any moment, you can retrieve the host state using
|The host is asking the user for permissions, or asking the backend for a Stream object.|
|The host is not streaming, but it is ready to. Stream might have started and then paused, or never started.|
|The host is currently streaming.|
You also have handy functions to navigate through the different states easily:
You can also, at any moment, access the underlying Stream object through
This object, especially the playback urls, can be shared to viewers to access the stream.
You can use
StreamHost.camera to configure everything related to camera, as explained here.
We also offer different
StreamHost.streamingMode options to choose between different audio/video sources:
StreamingMode.CAMERA_AND_AUDIO: default stream, with camera + microphone
StreamingMode.CAMERA_ONLY: no audio stream
StreamingMode.AUDIO_ONLY: no video stream
Events are subscribed to through the