Skip to main content
Version: 4.x.x

Stop HLS - iOS

Stopping HLS ends an ongoing HLS stream, so it is no longer available to viewers.

Stopping HLS​

  • stopHLS() of the Room class stops the interactive livestream of the room.
note
  • stopHLS() is async throws. Call it with try await inside a Task.
  • When the call is refused, it throws a VideoSDKError:
    • ERROR_ACTION_PERFORMED_BEFORE_ROOM_JOINED (3035) before you join the room, or after you leave it.
    • ERROR_ROOM_RECONNECTING (3065) while the room is reconnecting. Call the method again after the room reconnects.
  • If the request fails, for example because the server refuses it, the call throws and onError(error:) also receives STOP_HLS_FAILED (4017). Show the error only once.

Example​

func stopHLS() {
Task {
do {
try await self.room?.stopHLS()
} catch let error as VideoSDKError {
print("Stop HLS failed: \(error.name) (\(error.code)): \(error.message)")
} catch {
print("Stop HLS failed: \(error)")
}
}
}

Event associated with HLS​

  • onHlsStateChanged - Whenever the HLS state of the room changes, then onHlsStateChanged event will trigger.

  • You will get HLS_STOPPING and HLS_STOPPED status on calling stopHLS().

class RoomViewController: ObservableObject {
//...
// Add event listeners and join the room
room?.addEventListener(self)
//...
}

extension RoomViewController: RoomEventListener {
//...
func onHlsStateChanged(state: HLSState, hlsUrl: HLSUrl?) {
hlsState = state
switch (state) {
case .HLS_STARTING:
print("HLS is Starting")
case .HLS_STARTED:
print("HLS is Started")
case .HLS_PLAYABLE:
print("HLS is Playable Now!")
// once HLS is playable you will receive playbackHlsUrl and livestreamUrl
let playableURL = hlsUrl?.playbackHlsUrl ?? ""
let liveStreamURL = hlsUrl?.livestreamUrl ?? ""
case .HLS_STOPPING:
print("HLS is Stopping")
case .HLS_STOPPED:
print("HLS is Stopped")
@unknown default:
break
}
}
}
//...

API Reference​

The API references for all the methods utilized in this guide are provided below.

Got a Question? Ask us on discord