Developer Jul 31, 2022

How to build a live streaming app?

Get Your Own Development Resources

What is a Live Streaming App?

Live streaming technology allows you to broadcast, watch, create and share videos in real-time. All you need to be able to live stream is an internet-enabled device, like a smartphone or tablet, and a platform (such as a website or app) to live stream.

Live streaming apps are rapidly developing, given this trend's tremendous opportunities in many fields. Depending on the domain, the basic requirements for building a live streaming app differ as follows:

  1. Game live streaming app - The picture must be clear and smooth to construct a game live streaming app.
  2. Entertainment live streaming app - Building an entertainment app requires various interactive functions such as gifts, barrage, and mini-games.
  3. Shopping live streaming app - It must provide functions such as shopping cart and live broadcast playback.
  4. Sports live streaming app - It is necessary to ensure a clear and smooth picture and provide a variety of resolutions for users to choose from.
  5. Educational live streaming app - Interactive whiteboard, file sharing, screen sharing, and other functions are essential to delivering the best teaching experience to students.

Tall to an Expert ↓

Must-Have Features Of a Live Streaming app

Despite the differences, there are some standard functions that all live streaming apps should have, such as:

Client join/sign-in - A straightforward enrollment structure for the clients to make a record and sign in to the application with the certification.

Search -  A search box allowing users to search content by topic, popularity, trending, channel, location, or interests.

Client profile - Show the client's data and profile picture to companions and subscribers.

Live streaming - The app's core permits the client to record and communicate a live stream to individuals who subscribe to their channel or the public.

Chats - Adding a chat function helps the host communicate with the audience in real-time.

Building a live streaming app in different fields will require integrating some unique features. Relevant examples are:

Screen Sharing - For a game live streaming app, you must share the game screen with the audience through the screen sharing function.

Host PK - Required for the entertainment live streaming apps. Through the PK between anchors, one can enrich the content of the live streaming app, enhancing the audience's enthusiasm by sending gifts.

Shopping Cart - The live shopping streaming app provides a shopping portal for viewers to place orders and purchase products directly in the live streaming room.

Share whiteboard or file - The education live streaming app must share various teaching courseware, so providing functions such as shared whiteboard and transferred files to enrich the teaching form is necessary.

What is a Live Streaming SDK?

The Live Streaming App is complex, especially if each function is self-developed. It requires a vast technical team and consumes many human and financial resources.

Many companies encapsulate the standard functions of Live Streaming apps into SDK, thus, developing a Live Streaming app only needs to focus on business interaction development.

Among these functions:

Express SDK - Audio and video transmission service SDK encapsulates audio and video capture, preprocessing, encoding, transmission, decoding, rendering, and so on.

ZIM SDK - Message communication SDK, which encapsulates the transmission, and broadcasting of text messages, picture messages, video messages, and other messages, ability to notify.

SuperBoard SDK - Encapsulates interactive whiteboard, file management, file rendering, and other capabilities.

RoomKit SDK - Encapsulates a complete educational scene, including audio and video calls, barrage messages, shared whiteboards, shared files, equipment management, student management and other teaching scene logic.

Steps to Build a Live Streaming App

Prerequisites

Before you begin, make sure you complete the following steps:

Understand the process

The following diagram shows the basic process of creating a live room and a participant (user B) playing a stream published by the host (user A).

process of creating a live room

Integrate the ZEGOLive SDK

To integrate the SDK, do the following:

Download the Sample codes, copy the zegolive module to your project (create a new project if you don't have an existing project).

Add the following code to the settings.gradle file:

include ':zegolive'

Modify the build.gradle file of your application, add the following code to the dependencies node:

implementation project(':zegolive')
implementation project

Modify the build.gradle file of your project, add the following code to the repositories node:

maven { url 'https://www.jitpack.io' }
Modify the build.gradle
  1. Click sync now.

Initialize the ZEGOLive SDK

To initialize the ZEGOLive SDK, get the RoomManager instance, and pass the AppID of your project.

// The AppID you get from ZEGOCLOUD Admin Console. 
long appID = 214124124L;
// Initialize the SDK. We recommend you call this method when the application starts.
// The last parameter refers to the Application object of the ZEGOlive SDK.
ZegoRoomManager.getInstance().init(appID, this);

To receive event callbacks, call the setListener to listen for and handle various events as needed.

ZegoMessageService messageService = ZegoRoomManager.getInstance().messageService;
messageService.setListener(new ZegoMessageServiceListener() {
    // Implement the callback handling logic as needed.
});

ZegoUserService userService = ZegoRoomManager.getInstance().userService;
userService.setListener(new ZegoUserServiceListener() {
    // Implement the callback handling logic as needed.        
});

ZegoRoomService roomService = ZegoRoomManager.getInstance().roomService;
roomService.setListener(new ZegoRoomServiceListener() {
    // Implement the callback handling logic as needed. 
});

Log in

To access the ZEGOLive service, you must log in first.

  • For business security, you will need to provide a token for the ZIM SDK to validate the login privilege. For details, see Authentication.
  • For debugging, you can refer to our Sample code to generate tokens on your app client.
ZegoUserInfo user  = new ZegoUserInfo();
// Set the user related properties. 
user.setUserID("USER_ID");
user.setUserName("USER_NAME");

// Your token. 
String token = "xxx";  
ZegoRoomManager.getInstance().userService.login(user, token, new ZegoRoomCallback() {
    @Override
    public void onRoomCallback(int errorCode) {
        // Callback for the login result. 
    }
});

Start the local video preview

Before creating a live room to start live streaming, you can call the playVideoStream method to start the local video preview.

// The [userID] can be used to specify which user's view you want to view. 
// To preview your own local video view, pass in your userID.
// streamView view is a view for the local video preview.
ZegoRoomManager.getInstance().deviceService.playVideoStream(userID, streamView);

Create/Join a live room

  • You become a Host after creating a room, and you can take a seat and start live streaming upon creating.
  • You become a Participant after joining a live room, and you can watch the live streaming and be a co-host to interact.

To create a live room, call the createRoom method:

String roomID = "YOUR_ROOM_ID";
String roomName = "YOUR_ROOM_NAME";
ZegoRoomManager.getInstance().roomService.createRoom(roomID, roomName, token, new ZegoRoomCallback() {
   @Override
   public void onRoomCallback(int errorCode) {
   // Callback for the result of create a live room. 
   }
});

After a live room is created, to start live streaming, the host will need to call the takeSeat method to speak. And the SDK automatically publishes the streams when the host takes a seat successfully.

ZegoRoomManager.getInstance().userService.takeSeat(new ZegoRoomCallback(){
   @Override
   public void onRoomCallback(int errorCode) {
   // Callback for the returned result of take a seat.
   }
});

To join a live room, call the joinRoom method.

String roomID = "ROOM_ID";
ZegoRoomManager.getInstance().roomService.joinRoom(roomID, token, new ZegoRoomCallback() {
   @Override
   public void onRoomCallback(int errorCode) {
   // Callback for the result of join a live room. 
   }
});

After joining a live room, for a participant to watch the live streaming, he will need to call the playVideoStream method to play the host's published streams.

// The [userID] can be used to specify which user's view you want to view. 
// You can get the userID of the host in room info.
// streamView view is a view for the local video preview.
ZegoRoomManager.getInstance().deviceService.playVideoStream(userID, streamView);

Leave a live room

Before the host leaves the live room, he will need to call the leaveSeat to leave the seat first. And the SDK automatically stops publishing streams when the host leaves the seat successfully.

ZegoRoomManager.getInstance().userService.leaveSeat(new ZegoRoomCallback(){
   @Override
   public void onRoomCallback(int errorCode){
   // Callback for the result of leave a seat.
   }
});

To leave the live room, call the leaveRoom method. And the SDK stops all the stream publishing and playing operations simultaneously.

ZegoRoomManager.getInstance().roomService.leaveRoom(new ZegoRoomCallback() {
   @Override
   public void onRoomCallback(int errorCode) {
   // Callback for the result of leave a live room. 
   }
});

Log out

To finish the ZEGOLive service, call the logout method.

ZegoRoomManager.getInstance().userService.logout();

Deinitialize the ZEGOLive SDK

To deinitialize the SDK to make it uninitialized, call the uninit method.

ZegoRoomManager.getInstance().unInit();

Tags

ZEGOCLOUD

Building stable and high-quality cloud streaming services for real-time audio and video communications.