Live Streaming Kit
  • iOS
  • Android
  • Web
  • Flutter : Dart
  • React Native
  • Overview
  • Quick start
    • Quick start
    • Quick start (with cohosting)
  • Tutorial navigator
  • Enhance the livestream
    • PK battles
    • Screen sharing
    • Advanced beauty effects
    • Minimize livestream window
    • Send virtual gifts
    • Integrate Minigame
  • Customize the livestream
    • Set avatar for users
    • Hide components
    • Customize the preview page
    • Set a leave confirmation dialog
    • Customize the background
    • Add custom UI components
    • Customize the text message UI
    • Customize the member list view
    • Modify User Interface text
    • Customize the menu bar
    • Implement an audio-only live
    • Forcefully end a livestream room
    • Turn off camera during co-hosting
    • Set video resolution
    • Limit the maximum number of co-hosts
    • Host Avatar
    • Calculate live duration
    • Customize The CoHosting
    • Swipe Live Streaming
    • Customize the layout
  • FAQs
  • API Reference
    • API
    • Event
  • Migration guide
  • Documentation
  • Live Streaming Kit
  • Quick start
  • Quick start (with cohosting)

Quick start (with cohosting)

Last updated:2023-07-14 10:46

/Pics/ZegoUIKit/Flutter/live_with_cohosting2.gif

Prerequisites

​If you don't know how to create a project and obtain an app ID, please refer to this guide.

Integrate the SDK

Add ZegoUIKitPrebuiltLiveStreaming as dependencies

Run the following code in your project's root directory:

flutter pub add zego_uikit_signaling_plugin
flutter pub add zego_uikit_prebuilt_live_streaming

Import the SDK

Now in your Dart code, import the Live Streaming Kit SDK.

import 'package:zego_uikit_signaling_plugin/zego_uikit_signaling_plugin.dart';
import 'package:zego_uikit_prebuilt_live_streaming/zego_uikit_prebuilt_live_streaming';

Using the Live Streaming Kit

  • Specify the userID and userName for connecting the Live Streaming Kit service.
  • liveID represents the live stream you want to start or watch.
  • Set the config to the ZegoUIKitSignalingPlugin plug-in.
  • userID, userName, and liveID can only contain numbers, letters, and underlines (_).
  • Using the same liveID will enter the same live streaming.

With the same liveID, only one user can enter the live stream as host. Other users need to enter the live stream as the audience.

class LivePage extends StatelessWidget {
  final String liveID;
  final bool isHost;

  const LivePage({Key? key, required this.liveID, this.isHost = false}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: ZegoUIKitPrebuiltLiveStreaming(
        appID: yourAppID, // Fill in the appID that you get from ZEGOCLOUD Admin Console.
        appSign: yourAppSign, // Fill in the appSign that you get from ZEGOCLOUD Admin Console.
        userID: 'user_id',
        userName: 'user_name',
        liveID: liveID,
        config: isHost
            ? ZegoUIKitPrebuiltLiveStreamingConfig.host(
                plugins: [ZegoUIKitSignalingPlugin()],
              )
            : ZegoUIKitPrebuiltLiveStreamingConfig.audience(
                plugins: [ZegoUIKitSignalingPlugin()],
              ),
      ),
    );
  }
}

Then, you can start a live stream. And the audience can watch the live stream by entering the liveID.

Config your project

Android:

1. modify the compileSdkVersion

If your project is created with Flutter 2.x.x, you will need to open the your_project/android/app/build.gradle file, and modify the compileSdkVersion to 33.

compileSdkVersion

2. And in the same file, edit the minSdkVersion.

minSdkVersion 21

Pics/ZegoUIKit/Flutter/android_class_confusion.png

3. Add app permission.

Open the file your_project/app/src/main/AndroidManifest.xml, and add the following:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<img src="https://storage.zego.im/sdk-doc/Pics/ZegoUIKit/Flutter/live/permission_android.png" width=800>

4. Prevent code obfuscation.

To prevent obfuscation of the SDK public class names, do the following:

a. In your project's your_project > android > app folder, create a proguard-rules.pro file with the following content as shown below:

-keep class **.zego.** { *; } -keep class **.**.zego_zpns.** { *; }

b. Add the following config code to the release part of the your_project/android/app/build.gradle file.

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

Pics/ZegoUIKit/Flutter/android_class_confusion.png

iOS:

1. Add app permissions.

a. Open the your_project/ios/Podfile file, and add the following to the post_install do |installer| part:

# Start of the permission_handler configuration
target.build_configurations.each do |config|
  config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
    '$(inherited)',
    'PERMISSION_CAMERA=1',
    'PERMISSION_MICROPHONE=1',
  ]
end
# End of the permission_handler configuration

b. Open the your_project/ios/Runner/Info.plist file, and add the following to the dict part:

    <key>NSCameraUsageDescription</key>
    <string>We require camera access to connect</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>We require microphone access to connect</string>

2. Disable the Bitcode.

The following SDKs need to have Bitcode disabled:

  1. zego_zim
  2. zego_pns
  3. zego_express_engine

a. Open the your_project > iOS > Runner.xcworkspace file.

b. Select your target project, and follow the notes on the following two images to disable the Bitcode respectively.

Run & Test

Now you can simply click the Run or Debug button to run and test your App on the device.

/Pics/ZegoUIKit/Flutter/run_flutter_project.jpg

Resources

Page Directory