HLS Events - Android
The onHlsStateChanged event tells you the current state of HLS for the room.
onHlsStateChanged
- This event will be triggered when the room's HLS status changes.
- Override it in a
RoomEventListenerand register the listener withroom.addEventListener(). startHLS()returns before the stream can be played.HLS_STARTEDonly means the server accepted the request, so wait forHLS_PLAYABLE.stateis anHLSState:HLS_STARTING,HLS_STARTED,HLS_PLAYABLE,HLS_STOPPINGorHLS_STOPPED. A state outside them is not delivered.room.hlsStateholds the latest one. It is nevernull: it isHLS_STOPPEDuntil the first event, and is reset when the room is left.- When you receive
HLS_PLAYABLEstatus, you will also receivehlsUrl, anHLSUrlwith the URLs to play the HLS stream:playbackHlsUrlfor viewers, andlivestreamUrl, which follows the live edge.hlsUrlisnullwith every other state.
Example
Here is the usage of the event mentioned in this page.
private val roomEventListener: RoomEventListener = object : RoomEventListener() {
override fun onHlsStateChanged(state: HLSState, hlsUrl: HLSUrl?) {
when (state) {
HLSState.HLS_STARTING -> Log.d("onHlsStateChanged", "Room hls is starting")
HLSState.HLS_STARTED -> Log.d("onHlsStateChanged", "Room hls is started")
HLSState.HLS_PLAYABLE -> {
Log.d("onHlsStateChanged", "Room hls is playable now")
// on hls playable you will receive the playback URL
val playbackHlsUrl = hlsUrl?.playbackHlsUrl
}
HLSState.HLS_STOPPING -> Log.d("onHlsStateChanged", "Room hls is stopping")
HLSState.HLS_STOPPED -> Log.d("onHlsStateChanged", "Room hls is stopped")
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
//...
// add listener to room
room!!.addEventListener(roomEventListener)
}
API Reference
The API references for all the methods and events utilised in this guide are provided below.
Got a Question? Ask us on discord

