Stop HLS - Android
Stopping HLS ends the ongoing HLS stream, so it is no longer available to viewers.
Stopping HLS
- Call
stopHLS()on theRoomto stop the HLS stream.
note
stopHLS()is asuspendfunction. Call it from a coroutine, such aslifecycleScope.launch(fromandroidx.lifecycle:lifecycle-runtime-ktx).- It returns once the request is sent.
onHlsStateChangedreportsHLSState.HLS_STOPPEDwhen the stream has stopped. - If the request fails, it throws
VideoSDKException. - Called before the room is joined, or while it is reconnecting, it does nothing and reports
3035(ERROR_ACTION_PERFORMED_BEFORE_ROOM_JOINED) or3065(ERROR_ROOM_RECONNECTING) ononErrorinstead of throwing.
Example
findViewById<View>(R.id.btnStopHls).setOnClickListener { view: View? ->
lifecycleScope.launch {
try {
// Stop HLS
room!!.stopHLS()
} catch (e: VideoSDKException) {
Log.e("VideoSDK", "Stop HLS failed: ${e.code} ${e.name}")
}
}
}
Event associated with HLS
-
onHlsStateChanged - Whenever the room's HLS state changes, the
onHlsStateChangedevent will trigger with anHLSState. -
You will get the
HLS_STOPPINGandHLS_STOPPEDstates on callingstopHLS().
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 utilized in this guide are provided below.
Got a Question? Ask us on discord

