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 SDK 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:
1. 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.
2. 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.
3. 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).
4. 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.
5. 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.
6. 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 Flutter 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 screens. 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, as the best Agora live streaming SDK Flutter alternative, 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.
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.
Add live button
Insert two buttons, one to start life and one to watch live.
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
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';
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)));
}
Configure your project
- Android:
- You need to open the
your_project/android/app/build.gradle
file and modify thecompileSdkVersion
to 33.
- Add app permissions.
Open the fileyour_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" />
- 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'
- iOS:
- 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 to a live</string>
<key>NSMicrophoneUsageDescription</key>
<string>We require microphone access to connect to a live</string>
Run a Demo
Conclusion
Live streaming offers unparalleled potential as a growth engine for businesses when leveraged effectively. Opting for a live-streaming app could be the optimal strategy for enhancing your business or monetizing engaging content. By developing a video streaming app and creating your own streaming service, you can significantly expand your company’s reach and impact.
Embracing ZEGOCLOUD Live Streaming SDK can transform this potential into reality, providing robust, scalable solutions that ensure high-quality streaming experiences for your audience. This powerful tool is designed to meet the diverse needs of businesses looking to venture into live streaming, making it easier than ever to connect with viewers worldwide. We encourage you to explore how ZEGOCLOUD can support your growth and help you harness the full power of live streaming.
Read more:
Flutter Streaming FAQ
Q1: What is Flutter and how is it used in streaming apps?
Flutter is a cutting-edge, open-source UI software development kit, masterfully crafted by Google. Renowned for its versatility, Flutter enables the creation of seamlessly natively compiled applications suitable for mobile, web, and desktop platforms, all from a singular, unified codebase. Within the realm of streaming applications, Flutter’s prowess shines through its capability to forge smooth, aesthetically captivating user interfaces. Moreover, its robust architecture ensures unwavering, consistent performance across a diverse array of platforms, marking it as an indispensable tool in modern app development.
Q2: What are the challenges of using Flutter for streaming apps?
Some challenges of using Flutter for streaming apps include handling various video formats and codecs, ensuring smooth playback over different network conditions, and managing efficient memory and resource usage during streaming. Additionally, integrating advanced streaming features like adaptive bitrate streaming or DRM protection can be complex.
Q3: How does Flutter handle different screen sizes and orientations in streaming apps?
Flutter handles different screen sizes and orientations using a responsive design framework. It provides widgets and tools that automatically adapt to different screen dimensions and orientations. This is crucial in streaming apps for maintaining a consistent user experience across various devices, ensuring that video content scales and resizes correctly.
Talk to Expert
Learn more about our solutions and get your question answered.