Skip to main content
Version: 3.x.x

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 RoomEventListener and register the listener with room.addEventListener().
  • startHLS() returns before the stream can be played. HLS_STARTED only means the server accepted the request, so wait for HLS_PLAYABLE.
  • state is an HLSState: HLS_STARTING, HLS_STARTED, HLS_PLAYABLE, HLS_STOPPING or HLS_STOPPED. A state outside them is not delivered.
  • room.hlsState holds the latest one. It is never null: it is HLS_STOPPED until the first event, and is reset when the room is left.
  • When you receive HLS_PLAYABLE status, you will also receive hlsUrl, an HLSUrl with the URLs to play the HLS stream: playbackHlsUrl for viewers, and livestreamUrl, which follows the live edge. hlsUrl is null with 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