logo
On this page

Live list

With this feature, you can display the list of LIVEs on your homepage.

live list

How to integrate

Connect ZegoLiveStreamingOutsideLiveListController to ZegoUIKitPrebuiltLiveStreaming

you need assign the controller of ZegoLiveStreamingOutsideLiveList to controller of ZegoLiveStreamingOutsideLiveConfig, which is config.outsideLives.controller in ZegoUIKitPrebuiltLiveStreaming

1
Define a ZegoLiveStreamingOutsideLiveListController

You can play/stop the host audio & video by manually calling the API of this controller.

Untitled
final outsideLiveListController = ZegoLiveStreamingOutsideLiveListController();
1
Copied!
2
Add ZegoLiveStreamingOutsideLiveList on your widget

Add this list widget to the view where you want to display the live list.

Untitled
ZegoLiveStreamingOutsideLiveList(
  appID: /*input your AppID*/,
  appSign: /*input your AppSign*/,
  controller: outsideLiveListController,
),
1
Copied!
3
Connect ZegoLiveStreamingOutsideLiveListController to ZegoUIKitPrebuiltLiveStreaming
Untitled
ZegoUIKitPrebuiltLiveStreaming(
  ...
  config: ZegoUIKitPrebuiltLiveStreamingConfig(
    outsideLives: ZegoLiveStreamingOutsideLivesConfig(
      controller: outsideLiveListController,
    ),
  ),
),
1
Copied!
4
Update the live list to be displayed

You can update the entire live list at any time by updating the host list.

Untitled
outsideLiveListController.updateHosts([
  ZegoLiveStreamingOutsideLiveListHost(
    roomID: $live_id,
    user: ZegoUIKitUser(id: $user_id, name: $user_name),
  ),
]);
1
Copied!

Example

In the following example, a horizontal list of LIVEs is displayed, and clicking the enter button can join in the corresponding LIVE.

Untitled
class HomePage extends StatefulWidget {
 const HomePage({
   Key? key,
 }) : super(key: key);

 @override
 State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
 final liveListInfos = [
   {'live_id': $live_id_1, 'host_id': $host_id_1},
   {'live_id': $live_id_2, 'host_id': $host_id_2},
   {'live_id': $live_id_3, 'host_id': $host_id_3},
   {'live_id': $live_id_4, 'host_id': $host_id_4},
 ];

 final liveListController = ZegoLiveStreamingOutsideLiveListController();

 @override
 void initState() {
   super.initState();

   liveListController.updateHosts(
     liveListInfos
         .map((e) => ZegoLiveStreamingOutsideLiveListHost(
               user: ZegoUIKitUser(id: e['host_id']!, name: ''),
               roomID: e['live_id']!,
             ))
         .toList(),
   );
 }

 @override
 Widget build(BuildContext context) {
   return Scaffold(
     body: SafeArea(
       child: Container(
         height: 200,
         padding: const EdgeInsets.symmetric(horizontal: 10),
         child: ZegoLiveStreamingOutsideLiveList(
           appID: yourAppID,
           appSign: yourAppSign,
           controller: liveListController,
           style: ZegoLiveStreamingOutsideLiveListStyle(
             item: ZegoLiveStreamingOutsideLiveListItemStyle(
               foregroundBuilder: foreground,
             ),
           ),
         ),
       ),
     ),
   );
 }

 Widget foreground(
   BuildContext context,
   Size size,
   ZegoUIKitUser? user,
   String roomID,
 ) {
   return Align(
     alignment: Alignment.bottomCenter,
     child: ElevatedButton(
       child: Text('enter live'),
       onPressed: () {
         Navigator.push(
           context,
           MaterialPageRoute(
             builder: (context) => SafeArea(
               child: ZegoUIKitPrebuiltLiveStreaming(
                 appID: $your_app_id,
                 appSign: $your_app_sign,
                 userID: $user_id,
                 userName: $user_name,
                 liveID: roomID,
                 config: ZegoUIKitPrebuiltLiveStreamingConfig.audience(
                   plugins: [ZegoUIKitSignalingPlugin()],
                 )
                 ..outsideLives.controller = liveListController,
               ),
             ),
           ),
         );
       },
     ),
   );
 }
}
1
Copied!

How to manually start/stop playing the video and audio of the host on the live list

By default, the videos and audios of the host in the live list will automatically play. If you want to control them manually, please follow the steps below to achieve it:

1
Set to manual play mode
Untitled
ZegoLiveStreamingOutsideLiveList(
  config: ZegoLiveStreamingOutsideLiveListConfig(
    playMode: ZegoOutsideRoomAudioVideoViewListPlayMode.manualPlay,
  ),
);
1
Copied!
2
Start/Stop playing by calling the following APIs.

Please refer to the API documentation for more information.

  • startPlayOne(ZegoLiveStreamingOutsideLiveListHost host)
  • stopPlayOne(ZegoLiveStreamingOutsideLiveListHost host)
  • addHost(ZegoLiveStreamingOutsideLiveListHost host, {bool startPlay = true})
  • removeHost(ZegoLiveStreamingOutsideLiveListHost host)
  • updateHosts(List<ZegoLiveStreamingOutsideLiveListHost> hosts, {bool startPlay = true})

API

ZegoLiveStreamingOutsideLiveListController

  • startPlayAll:

    Play videos and audios of all hosts in the live list.

  • stopPlayAll:

    Stop playing videos and audios of all hosts in the live list.

  • startPlayOne(ZegoLiveStreamingOutsideLiveListHost host):

    Play the video and audio of the host. If the host is not in the live list, calling this interface will have no effect. You can use addHost to add and play the video and audio of a host.

  • stopPlayOne(ZegoLiveStreamingOutsideLiveListHost host):

    Stop playing the video and audio of the host. If the host is not in the live list, calling this interface will have no effect.

  • updateHosts(List<ZegoLiveStreamingOutsideLiveListHost> hosts, {bool startPlay = true}):

    Update the host list to update the entire live list.

  • addHost(ZegoLiveStreamingOutsideLiveListHost host, {bool startPlay = true}):

    Add a host to add a live item in the live list.

  • removeHost(ZegoLiveStreamingOutsideLiveListHost host):

    Remove the live item corresponding to the host in the live list.

Config

ZegoLiveStreamingOutsideLiveListConfig

AttributeDescriptionType
playModePlay mode, default is auto play. If you want to manually control, set it to manualPlay, and call the APIs of ZegoLiveStreamingOutsideLiveListController to control it.ZegoOutsideRoomAudioVideoViewListPlayMode
videoConfiguration parameters for audio and video, such as Resolution, Frame rate, Bit rate. The default is ZegoUIKitVideoConfig.preset180P()ZegoUIKitVideoConfig?

ZegoOutsideRoomAudioVideoViewListPlayMode

Prototype
/// play mode
enum ZegoOutsideRoomAudioVideoViewListPlayMode {
 /// All streams (video and audio) in visible area will be automatically played internally.
 autoPlay,

 /// Control the play timing by yourself, and you need to manually call the API to play the stream (video and audio).
 /// [ZegoOutsideRoomAudioVideoViewListController]
 /// - startPlayOne
 /// - stopPlayOne
 /// - startPlayAll
 /// - stopPlayAll
 manualPlay,
}
1
Copied!

ZegoLiveStreamingOutsideLiveListStyle

AttributeDescriptionType
scrollDirectionScroll direction, default is horizontalAxis
borderRadiusBorder radiusdouble
borderColorBorder colorColor
borderColorOpacityBorder color opacitydouble
backgroundColorBackground colorColor
backgroundColorOpacityBackground color opacitydouble
loadingBuilderLoading builder, return Container() if you want hide itWidget? Function(BuildContext context)?
itemItem styleZegoLiveStreamingOutsideLiveListItemStyle

ZegoLiveStreamingOutsideLiveListItemStyle

AttributeDescriptionType
useVideoViewAspectFillVideo view mode. Set it to true if you want the video view to scale proportionally to fill the entire view, potentially resulting in partial cropping. Set it to false if you want the video view to scale proportionally, potentially resulting in black borders.bool
sizeAspectRatioAspect ratiodouble
foregroundBuilderForeground builder, you can display something you want on top of the view, foreground will always showWidget Function(BuildContext context, Size size, ZegoUIKitUser? user, String roomID, )?
backgroundBuilderBackground builder, you can display something when user close cameraWidget Function(BuildContext context, Size size, ZegoUIKitUser? user, String roomID,)?
marginMarginEdgeInsetsGeometry
borderRadiusBorder radiusdouble
borderColorBorder colorColor
borderColorOpacityBorderColor opacitydouble
loadingBuilderLoading builder, return Container() if you want hide itWidget? Function(BuildContext context, ZegoUIKitUser? user, String roomID,)?
avatarCustom avatarZegoAvatarConfig?