Skip to main content
Version: 5.x.x

Stop HLS - Flutter

This could refer to stopping the transmission of an ongoing HLS stream, which would mean the stream is no longer available to viewers.

Stopping HLS​

stopHLS() stops the interactive livestream of the room. Call it on the Room object. It returns a Future. Await it and catch VideoSDKError, which it throws when HLS cannot be stopped.

Example​

import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class RoomScreen extends StatefulWidget {
...
}

class _RoomScreenState extends State<RoomScreen> {
late Room _room;

@override
void initState() {
...
}

@override
Widget build(BuildContext context) {
return Column(
children:[
ElevatedButton(
onPressed: () async {
try {
await _room.stopHLS();
} on VideoSDKError catch (error) {
log("Could not stop HLS: ${error.code} ${error.name}");
}
},
child: const Text("Stop HLS"),
),
]
);
}
}

Event associated with HLS​

  • hlsStateChanged - Fires whenever the room's HLS state changes. The handler receives the state and an HLSUrl?.

  • After you call stopHLS(), you get the HLS_STOPPING and then the HLS_STOPPED state.

import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class RoomScreen extends StatefulWidget {
...
}

class _RoomScreenState extends State<RoomScreen> {
late Room room;

@override
void initState() {
...

setupRoomEventListener();
}

@override
Widget build(BuildContext context) {
return YourRoomWidget();
}

void setupRoomEventListener() {
room.on(Events.hlsStateChanged, (String state, HLSUrl? hlsUrl) {
//State can be :: HLS_STARTING
//State can be :: HLS_STARTED
//State can be :: HLS_PLAYABLE
//State can be :: HLS_STOPPING
//State can be :: HLS_STOPPED
log("Room HLS state : $state");
if (state == "HLS_STOPPING") {
log("HLS Stopping");
}
if (state == "HLS_STOPPED") {
log("HLS Stopped");
}
});
}
}

Custom Template​

With VideoSDK, you can also use your own custom designed layout template to livestream the rooms. In order to use the custom template, you need to create a template for which you can follow this guide. Once you have setup the template, you can use the REST API to start the livestream with the templateUrl parameter.

API Reference​

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

Got a Question? Ask us on discord