Talk to us
Talk to us
menu

How to Build a Flutter Live Streaming App

How to Build a Flutter Live Streaming App

Live streaming has become an essential means of distributing media content to people worldwide. However, setting up and maintaining a live-streaming platform can be challenging, despite its benefits of capturing people’s attention and providing immediate experiences. This article will introduce the ZEGOCLOUD platform to quickly build a Flutter streaming app.

How Does Live Streaming Work?

Live streaming is transmitting video and audio content over the internet in real-time. Unlike traditional broadcast methods, live streaming does not require the content to be stored before it can be viewed, allowing for immediate delivery and interaction. Before starting a Flutter live streaming app development, you need to know how live streaming works:

Capture

The process begins with capturing the video and audio content. This could be anything from a person speaking into a webcam, a live concert, a gaming session, or a sports event. The video and audio signals are captured using a camera and microphone.

Encoding

When video and audio are captured, the data is initially uncompressed, making it too large to transmit over the internet efficiently. The data is compressed into a digital format suitable for transmission using an encoder to solve this. This encoder can be a hardware device or a software application. Additionally, the encoder breaks the data into smaller packets that can be easily transmitted over the internet.

Transmission

The encoded video and audio data is then transmitted over the internet to the streaming server. This is typically done using RTMP (Real-Time Messaging Protocol) or RTSP (Real-Time Streaming Protocol).

Streaming Server

The streaming server receives the encoded data and prepares it for distribution to the viewers. It does this by re-encoding the data into various formats and bitrates to accommodate viewers with different device types and internet connection speeds. This process is known as transcoding.

Distribution

The streaming server then distributes the stream to the viewers over the internet. This is typically done using a content delivery network (CDN) to ensure the stream can reach viewers worldwide with minimal latency.

Decoding and Playback

Finally, the viewer’s device receives the stream, decodes it into video and audio data, and plays it back in real-time. The viewer’s media player or web browser handles this process.

Interaction

In many live streams, there’s also a level of interaction between the streamer and the viewers. This can be in the form of live chats, votes, or other forms of engagement.

Why ZEGOCLOUD SDK for Live Streaming App

ZEGOCLOUD Live Streaming SDK provides a range of functions, such as audio and video capture, encoding, streaming, playback, transcoding, and cloud recording. Developers can easily integrate live streaming capabilities into their Flutter apps.

It supports different video qualities, including high definition, standard definition, and smooth, and provides rich audio and video processing capabilities such as filters, beautification, and green screen. You can implement real-time messaging and co-streaming features, making it easy to build interactive live-streaming applications. It is well-documented, with sample code available to help developers get started with Flutter live-streaming app development quickly.

Additionally, ZEGOCLOUD provides every developer with brand-new prebuilt UIKits and 50+ UI Components. It supports cross-platform, including iOS, Android, Web, Flutter, and React Native. Through it, You can complete the development of a live-streaming app within 10 minutes.

Flutter Live Streaming Kit handles all the logic and UI of the live streaming function. Include:

  • UI and interaction of the live Streaming module
  • Message sending and display
  • Audio and video data transmission
  • Camera and microphone management
  • Live Viewer Statistics

You only need to implement business-related logic. For example:

  • User login registration
  • Live List Management
  • Top up and send gifts, etc.
live streaming kit

Preparation

  • A ZEGOCLOUD developer account–Sign up
  • Flutter 1.12 or later.
  • Basic understanding of Flutter development

Implement live streaming

Create Project

Run the following code to create a new project.

flutter create --template app.
create project

Add live button

Insert two buttons, one to start life and one to watch live.

add live button
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(title: 'Flutter Demo', home: HomePage());
  }
}

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                  child: const Text('Start a live'),
                  onPressed: () => jumpToLivePage(context, isHost: true)),
              ElevatedButton(
                  child: const Text('Watch a live'),
                  onPressed: () => jumpToLivePage(context, isHost: false)),
            ],
          ),
        ),
      ),
    );
  }

  jumpToLivePage(BuildContext context, {required bool isHost}) {}
}

Set ZegoUIKitPrebuiltLiveStreaming as a dependency

Run the following command in your project root directory:

flutter pub add zego_uikit_prebuilt_live_streaming
add live streaming sdk

Import the SDK

Now in your Dart code, import the prebuilt LiveStreaming Kit SDK.

import 'package:zego_uikit_prebuilt_live_streaming/zego_uikit_prebuilt_live_streaming.dart';
import live streaming sdk

Implement live streaming

Use ZegoUIKitPrebuiltLiveStreaming to quickly build a live-streaming page

class LivePage extends StatelessWidget {
  const LivePage({Key? key, this.isHost = false}) : super(key: key);
  final bool isHost;

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: ZegoUIKitPrebuiltLiveStreaming(
        appID: , // use your appID
        appSign: 'yourAppSign', // use your appSign
        userID: userID,
        userName: 'user_$userID',
        liveID: 'testLiveID',
        config: isHost
            ? ZegoUIKitPrebuiltLiveStreamingConfig.host()
            : ZegoUIKitPrebuiltLiveStreamingConfig.audience(),
      ),
    );
  }
}

Now, you can create a new live or watch a live one by navigating to this live page.

void jumpToLivePage(BuildContext context, {required bool isHost}) {
  Navigator.push(context, MaterialPageRoute(builder: (context) => LivePage(isHost: isHost)));
}
implement live streaming

Configure your project

  • Android:
  1. You need to open the your_project/android/app/build.gradle file and modify the compileSdkVersion to 33.
compile sdk version
  1. Add app permissions.
    Open the file your_project/app/src/main/AndroidManifest.xml, and add the following code:
   <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" />
permission android
  1. 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.** { *; }

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'
android class confusion
  • 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
permission podfile

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 to a live</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>We require microphone access to connect to a live</string>
permission ios

Run a Demo

Conclusion

Live streaming can be the best growth engine for businesses if utilized well. A live-streaming app might be the most excellent option for running a business or earning money through exciting content. Develop a video streaming app, create your own streaming service, and grow your company.

Talk to Expert

Learn more about our solutions and get your question answered.

Talk to us

Take your apps to the next level with our voice, video and chat APIs

Free Trial
  • 10,000 minutes for free
  • 4,000+ corporate clients
  • 3 Billion daily call minutes

Stay updated with us by signing up for our newsletter!

Don't miss out on important news and updates from ZEGOCLOUD!

* You may unsubscribe at any time using the unsubscribe link in the digest email. See our privacy policy for more information.