Because of a conversation with Musk, ClubHouse caught fire worldwide and reached a staggering 9.6 million monthly downloads.
Faced with a new social model, how to quickly clone Clubhouse's social gameplay. Enrich the interaction form of your own application.
Today we will introduce how to use ZEGOCLOUD's ZEGOLiveAudioRoom SDK to quickly build a Social Audio App in 10 minutes.
Prerequisites
- Create a project in ZEGOCLOUD Admin Console.
- Contact us to activate the Live Audio Room service.
Understand the process
The following diagram shows the basic process of creating a live audio room and taking speaker seats to speak:
Integrate the zegoliveaudioroom SDK
To integrate the SDK, do the following:
- Download the Sample codes, copy the
zegoliveaudioroom
module to your project (if you have no project, create a new one). -
Add the following code to the
settings.gradle
file:
include ':zegoliveaudioroom'
-
Modify the
build.gradle
file of your application, add the following code to thedependencies
node:
implementation project(':zegoliveaudioroom')
-
Modify the
build.gradle
file of your project, add the following code to therepositories
node:
maven { url 'https://www.jitpack.io' }
- Click
sync now
.
Add permissions
Permissions can be set as needed.
Open the file app/src/main/AndroidManifest.xml
, and add the following code:
Note: For Android 6.0 or later, some important permissions must be requested at runtime rather than declared statically in the file
AndroidMainfest.xml
, therefore, you need to add the following code to do so (requestPermissions is a method of an Android Activity).
Prevent class name obfuscation
To prevent the ZEGOCLOUD SDK public class names from being obfuscated, you can add the following code in the file proguard-rules.pro
.
-keep class **.zego.**{*;}
Initialize the zegoliveaudioroom SDK
To initialize the zegoliveaudioroom SDK, get the ZegoRoomManager
instance, pass the AppIDof your project.
To receive event callbacks, call the setListener
to listen for and handle various events as needed.
Log in
To access the signaling service of Live Audio Room with the zegoliveaudioroom
SDK, you must log in first.
Create/Join a live audio room
- You become a Host after creating a live audio room, and you owe more permissions, such as closing untaken speaker seats, removing a specified listener from the speaker seat, etc.
- You become a Listener after joining a live audio room, you can take a speaker seat to be a speaker or leave the speaker seat to become a listener again.
To create a live audio room, call the createRoom
method:
To join a live audio room, call the joinRoom
method:
Send/Receive messages in the room
In a live audio room, both Host and Listeners can send and receive messages.
To send messages, call the sendTextMessage
method with message content.
To receive messages, listen for the ZegoMessageServiceListener
callback.
Take a speaker seat
To take a speaker seat to speak, call the takeSeat
method. And the SDK publishes streams simultaneously.
When there is a new listener takes a seat and becomes a speaker, all participants in the room receive notifications through the ZegoSpeakerSeatServiceListener
callback. You can set up a UI refresh action for this callback as needed.
Sign up with ZEGOCLOUD, get 10,000 minutes free every month.
Did you know? š
Like and Follow is the biggest encouragement to me
Follow me to learn more technical knowledge
Thank you for reading :)
Learn more
This is one of the live technical articles. Welcome to other articles:
Top comments (0)