Click the search button below to search documentation or error code
ZEGOCLOUD's easy example is a simple wrapper around our RTC product. You can refer to the sample code for quick integration.
- Android Studio Bumblebee or later
- An Android device or Simulator that is running on Android 5.1 or later and supports audio and video. We recommend you use a real device.
- Create a project in ZEGOCLOUD Admin Console. For details, see ZEGO Admin Console - Project management.
- Clone the easy example Github repository.
You need to modify appID
and serverSecret
to your own account, which can be obtained in the ZEGO Admin Console.
-
Connect the Android device to your computer.
-
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.
- 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'
}
- 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' }
}
}
- 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 express directory to your project
The calling sequence of the SDK interface is as follows: createEngine --> joinRoom --> setLocalVideoView/setRemoteVideoView --> leaveRoom
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);
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:
- call scene:[.autoPlayVideo, .autoPlayAudio, .publishLocalAudio, .publishLocalVideo]
- Live scene - host: [.autoPlayVideo, .autoPlayAudio, .publishLocalAudio, .publishLocalVideo]
- Live scene - audience:[.autoPlayVideo, .autoPlayAudio]
- Chat room - host:[.autoPlayAudio, .publishLocalAudio]
- 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);
}
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 {
}
}
When you want to leave the room, you can call the leaveroom interface.
ExpressManager.getInstance().leaveRoom();