How to Build a Clubhouse Clone App with Android and ZEGOCLOUD - A Social Audio App Development
Tags: android, mobile, programming, tutorial
Published: 2022-06-29 09:00:14

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](https://docs.zegocloud.com/article/13746.html?_source=dev&article=20) to quickly build a Social Audio App in 10 minutes.

![Demo](https://resource.zegocloud.com/content_resource/2022/06/29/demo.gif)


## Prerequisites

* Create a project in [ZEGOCLOUD Admin Console](https://console.zegocloud.com?_source=dev&article=20). 
* [Contact us](https://www.zegocloud.com/talk?_source=dev&article=20) 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:  
![process](https://resource.zegocloud.com/content_resource/2022/06/29/16563153921560.png)

## Integrate the zegoliveaudioroom SDK

To integrate the SDK, do the following:

1. Download the [Sample codes](https://github.com/ZEGOCLOUD/live_audio_room_android), copy the `zegoliveaudioroom` module to your project (if you have no project, create a new one).
2. Add the following code to the `settings.gradle` file:
    
    ```gradle
    include ':zegoliveaudioroom'
    ```
3. Modify the `build.gradle` file of your application, add the following code to the `dependencies` node: 

    ```gradle
    implementation project(':zegoliveaudioroom')
    ```
    
![build.gradle](https://resource.zegocloud.com/content_resource/2022/06/29/16563155088049.png)

4. Modify the `build.gradle` file of your project, add the following code to the `repositories` node: 
    
    ```gradle
    maven { url 'https://www.jitpack.io' }
    ```
    
  ![repositories](https://resource.zegocloud.com/content_resource/2022/06/29/16563156312553.png)


5. Click `sync now`.

## Add permissions

Permissions can be set as needed.

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

{% embed https://gist.github.com/larryluoo/156d00974f24a01a28bbb687646b0457 %}


> 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).

{% embed https://gist.github.com/larryluoo/087a05504252e465be353c09866e6867 %}

## 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`.

```java
-keep class **.zego.**{*;}
```

## Initialize the zegoliveaudioroom SDK

To initialize the zegoliveaudioroom SDK, get the `ZegoRoomManager` instance, pass the AppIDof your project. 

{% embed https://gist.github.com/larryluoo/684b5dbfadbf6722e40c9fd25e3a99dc %}


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

{% embed https://gist.github.com/larryluoo/883a5d2d4086317de0b6668a550b84a1 %}

## Log in 

To access the signaling service of Live Audio Room with the `zegoliveaudioroom` SDK, you must log in first.

{% embed https://gist.github.com/larryluoo/e57efaa1f7699447b460bd91670ba36e %}

## 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: 

{% embed https://gist.github.com/larryluoo/0ba8e01fdd2a3fa5c637ec9216593a89 %}


To join a live audio room, call the `joinRoom` method:

{% embed https://gist.github.com/larryluoo/ab441941b29aafabe838b251401dad56 %}


## 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.

{% embed https://gist.github.com/larryluoo/5b52805bcabe2d1355b63e630cc6fd08 %}

To receive messages, listen for the `ZegoMessageServiceListener` callback. 

{% embed https://gist.github.com/larryluoo/8bf5364517b0d9c11803cfdb4894a05c %}

## Take a speaker seat

To take a speaker seat to speak, call the `takeSeat` method. And the SDK publishes streams simultaneously. 

{% embed https://gist.github.com/larryluoo/18b4edb5bdaae08e31fa298193dd30af %}

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.

{% embed https://gist.github.com/larryluoo/df02efba82d45656bbdafeb84754e3cb %}

---

[Sign up](https://console.zegocloud.com/account/signup?_source=dev&article=20) 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:

{% embed https://dev.to/davidrelo/movies-together-online-in-a-few-hours-source-code-inside-40o0 %}

{% embed https://dev.to/davidrelo/all-live-streaming-features-in-one-article-29n6 %}

{% embed https://dev.to/davidrelo/improve-live-streaming-experience-with-stream-mixing-345o %}