Calculate live duration
This doc describes how to calculate the livestream duration through configuration.

To calculate the livestream duration, do the following:
-
Set the
isVisibleproperty ofZegoLiveStreamingDurationConfigto display the current timer. (It is displayed by default) -
Assuming that the livestream duration is 5 minutes, the livestream will automatically end when the time is up (refer to the following code). You will be notified of the end of the livestream duration through
ZegoLiveStreamingDurationEvents.onDurationUpdate. To end the livestream, you can call theleavemethod ofZegoUIKitPrebuiltLiveStreamingController.
class LivePage extends StatefulWidget {
final String liveID;
final bool isHost;
const LivePage({
Key? key,
required this.liveID,
this.isHost = false,
}) : super(key: key);
@override
State<StatefulWidget> createState() => LivePageState();
}
class LivePageState extends State<LivePage> {
@override
Widget build(BuildContext context) {
return SafeArea(
child: ZegoUIKitPrebuiltLiveStreaming(
appID: yourAppID /*input your AppID*/,
appSign: yourAppSign /*input your AppSign*/,
userID: 'userID',
userName: 'userName',
liveID: widget.liveID,
events: ZegoUIKitPrebuiltLiveStreamingEvents(
duration: ZegoLiveStreamingDurationEvents(
onUpdate: (Duration duration) {
if (duration.inSeconds == 5 * 60) {
ZegoUIKitPrebuiltLiveStreamingController().leave(context);
}
},
)),
config: (
widget.isHost
? ZegoUIKitPrebuiltLiveStreamingConfig.host(
plugins: [ZegoUIKitSignalingPlugin()],
)
: ZegoUIKitPrebuiltLiveStreamingConfig.audience(
plugins: [ZegoUIKitSignalingPlugin()],
),
)..duration.isVisible = true,
),
);
}
}
