Skip to content

Yerannnnnn/easy_example_android

 
 

Repository files navigation

ZEGOCLOUD easy example

Platform ZEGOCLOUD

Click the search button below to search documentation or error code

image

ZEGOCLOUD's easy example is a simple wrapper around our RTC product. You can refer to the sample code for quick integration.

Getting started

Prerequisites

Clone the repository

  1. Clone the easy example Github repository.

Modify the project configurations

You need to modify appID and serverSecret to your own account, which can be obtained in the ZEGO Admin Console.

Run the sample code

  1. Connect the Android device to your computer.

  2. Open Android Studio, select the Android device you are using,click the Run 'app' in the upper center to run the sample code and experience the Live Audio Room service.

Integrate the SDK into your own project

Introduce SDK

  1. declare the dependency for the ZegoExpressEngine Android library in your module (app-level) Gradle file (usually app/build.gradle).
dependencies {
    // Import the zego express engine
    implementation 'com.github.zegolibrary:express-video:2.17.1'
}
  1. In your setting.gradle file, add the jitpack maven .
    pluginManagement {
    repositories {
        
        maven { url 'https://www.jitpack.io' }
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        maven { url 'https://www.jitpack.io' }
    }
}
  1. to Run the app,you may need to process the dynamic permissions request.
  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.RECORD_AUDIO" />
  <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.WAKE_LOCK" />

declare them in xml and request Manifest.permission.CAMERA and Manifest.permission.RECORD_AUDIO in the runtime.

Copy the source code

Copy the express directory to your project

Method call

The calling sequence of the SDK interface is as follows: createEngine --> joinRoom --> setLocalVideoView/setRemoteVideoView --> leaveRoom

Create engine

Before using the SDK function, you need to create the SDK first. We recommend creating it when the application starts. The sample code is as follows:

 ExpressManager.getInstance().createEngine(getApplication(), AppCenter.appID);

Join room

When you want to communicate with audio and video, you need to call the join room interface first. According to your business scenario, you can set different audio and video controls through options, such as:

  1. call scene:[.autoPlayVideo, .autoPlayAudio, .publishLocalAudio, .publishLocalVideo]
  2. Live scene - host: [.autoPlayVideo, .autoPlayAudio, .publishLocalAudio, .publishLocalVideo]
  3. Live scene - audience:[.autoPlayVideo, .autoPlayAudio]
  4. Chat room - host:[.autoPlayAudio, .publishLocalAudio]
  5. Chat room - audience:[.autoPlayAudio]

The following sample code is an example of a call scenario:

   private void joinRoom(Callback callback) {
        String username = binding.username.getText().toString();
        String roomid = binding.roomid.getText().toString();
        String userID = System.currentTimeMillis() + "";
        ZegoUser user = new ZegoUser(userID, username);
        String token = ExpressManager.generateToken(userID, AppCenter.appID, AppCenter.serverSecret);
        int mediaOptions = ZegoMediaOptions.autoPlayAudio | ZegoMediaOptions.autoPlayVideo |
            ZegoMediaOptions.publishLocalAudio | ZegoMediaOptions.publishLocalVideo;
        ExpressManager.getInstance().joinRoom(roomid, user, token, mediaOptions, callback);
    }

set video view

If your project needs to use the video communication function, you need to set the View for displaying the video, call setLocalVideoView for the local video, and call setRemoteVideoView for the remote video.

setLocalVideoView:

   ExpressManager.getInstance().setLocalVideoView(binding.localTexture);

setLocalVideoView:

    public void onRoomUserUpdate(String roomID, ZegoUpdateType updateType, ArrayList<ZegoUser> userList) {
                if (updateType == ZegoUpdateType.ADD) {
                    for (int i = 0; i < userList.size(); i++) {
                        ZegoUser user = userList.get(i);
                        TextureView remoteTexture = binding.remoteTexture;
                        ExpressManager.getInstance().setRemoteVideoView(user.userID, remoteTexture);
                    }
                } else {
                    
                }
            }

leave room

When you want to leave the room, you can call the leaveroom interface.

 ExpressManager.getInstance().leaveRoom();

About

No description, website, or topics provided.

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%