Real-Time Video Call

This section introduces how to use basic functions of video SDK to use a video call. For deeper understanding of the functions, see information about advanced functions or get help from access personnel.

1 Prerequisites

Before you start, ensure that the following are available:

  • Android Studio 3.0 or above
  • Android SDK API 16 or above
  • Mobile device running Android 4.1 or above
  • Valid Jocloud account (valid APPID and APPSECRET). See details in APPID Application.

2 Development Environment Preparation

After the preceding prerequisites are met, SDK development can be started.

2.1 Create a Project

  1. Open Android Studio and click Start a new Android Studio project.
  2. Choose Phone and Tablet > Empty Activity, and then click Next.
  3. Enter the following contents:
  • Name: project name, for example, mouselive-android
  • Package name: Project package name, for example, com.jocloud.mouselive
  • Project location: Project saving path
  • Language: Programing language, for example, Java
  • Minimum API level: The minimum API level of the project
  1. Click Finish. Follow the on-screen instructions, if any, to install the plug-ins.

2.2 Integrate an SDK

  1. Locate build.gradle from the root directory of the project, open it, and add maven source:
buildscript {
    repositories {
        jcenter()
        maven {url "https://dl.bintray.com/yyqapm/maven"}
    }
}

allprojects {
    repositories {
        jcenter()
        maven {url "https://dl.bintray.com/yyqapm/maven"}
    }
}
  1. Add dependencies to the used SDK modules:
dependencies {
    implementation 'com.rtc.thunder:thunderbolt:x.y.z' //For X.Y.Z, please fill in a specific SDK version number, such as 2.8.2.  
}
  1. Add permissions required by SDK to the used SDK modules:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.xxx.xxxx">
    .....
    //Add permission
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
 

    //Add software features
    <uses-feature android:name="android.hardware.audio.low_latency" />
    <uses-feature android:name="android.hardware.audio.pro" />
    <uses-feature android:name="android.hardware.microphone" android:required="true" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-feature android:name="android.hardware.camera" android:required="true" />
    <uses-feature android:name="android.hardware.camera.front" android:required="true" />
</manifest>
  1. Anti-code obfuscation:

If code obfuscation is enabled during application compilation, the obfuscation must be prevented. Add the following information to the rule file proguard-rules.pro (/app/proguard-rules.pro) to prevent mixing public names in the library:

-keep class com.rtc.thunder.** { *; }
-keep class org.webrtc.audioengine.** { *; }
-keep class com.yy.yyvideolib.** { *; }
-keep class com.yy.yyvideoplayer.** { *; }
-keep class com.yy.android.medialibrary.audiocodec.** { *; }
  1. Click Sync to synchronize the project, and integrate.

3. Real-Time Video Interaction

After SDK integration, we can realize the real-time video call by SDK. The following figure shows the time sequence of API calling during a video call:

Time Sequence of Real-Time Video Call

3.1 Dynamic Permission Application

Call checkSelfPermission. When enabling Activity, check and obtain camera and microphone permissions of a mobile device.

private static final String[] REQUEST_PERMISSIONS = new String[]{
        Manifest.permission.CAMERA,
        Manifest.permission.WRITE_EXTERNAL_STORAGE,
        Manifest.permission.READ_EXTERNAL_STORAGE,
        Manifest.permission.INTERNET,
        Manifest.permission.ACCESS_NETWORK_STATE,
        Manifest.permission.RECORD_AUDIO,
        Manifest.permission.MODIFY_AUDIO_SETTINGS,
        Manifest.permission.BLUETOOTH,
        Manifest.permission.BLUETOOTH_ADMIN
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video_chat_view);


    if (checkSelfPermission(REQUESTED_PERMISSIONS[0], PERMISSION_REQ_ID) &&
        checkSelfPermission(REQUESTED_PERMISSIONS[1], PERMISSION_REQ_ID) &&
        checkSelfPermission(REQUESTED_PERMISSIONS[2], PERMISSION_REQ_ID)) {
      // TODO:
      // After obtaining permission, initialize SDK and join channel.
    }
}

private boolean checkSelfPermission(String permission, int requestCode) {
    if (ContextCompat.checkSelfPermission(this, permission) !=
            PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, REQUESTED_PERMISSIONS, requestCode);
        return false;
    }

    return true;
}

3.2 Create ThunderEngine

Before calling other Thunder APIs, create and initialize the ThunderEngine object.

You should fill in the APPID of the project in this step. See the following steps to create a project and get [APPID] in Console.

ThunderEngine.createEngine(Context context,String appId,long sceneId,ThunderEventHandler handler);
ThunderEngine.setArea(isChina ?
                ThunderRtcConstant.AreaType.THUNDER_AREA_DEFAULT :
                ThunderRtcConstant.AreaType.THUNDER_AREA_FOREIGN);

See details in API Manual about createEngine, createWithLoop, and setArea.

When creating ThunderEngine, you should monitor SDK events and status callback through ThunderEventHandler as required by the scenario. For example:

public void onTokenWillExpire() {}
public void onConnectionStatus(){}
public void onRemoteVideoStopped(String uid, boolean stop) {}
  • You can also process callbacks in ThunderEventHandler based on scenario requirements. See details in API Document.

3.3 Set Room Profiles and Join a Room

Before joining a room, set room profiles to obtain better user experience.

Note: when joining a room, provide a token. See Generate Token to obtain a token.

ThunderEngine.setMediaMode(isAudio ?
                ThunderRtcConstant.ThunderRtcProfile.THUNDER_PROFILE_ONLY_AUDIO :
                ThunderRtcConstant.ThunderRtcProfile.THUNDER_PROFILE_NORMAL);
ThunderEngine.setRoomMode(int mode);
ThunderEngine.setAudioConfig(int profile,int commutMode,int scenarioMode);
ThunderEngine.joinRoom(byte[] token, String roomName, String uid);

See details in API Manual about setMediaMode, setRoomMode, and joinRoom.

3.4 Enable Local Preview and Publish

  1. Enable local preview video:
ThunderVideoCanvas canvas = new ThunderVideoCanvas(ThunderPreviewView view, scaleMode, uid);
ThunderEngine.setLocalCanvasScaleMode(scaleMode);
ThunderEngine.setLocalVideoCanvas(canvas);
ThunderEngine.startVideoPreview();

See details in API Manual about setLocalVideoCanvas and startVideoPreview.

  1. Publish local video:
ThunderEngine.stopLocalVideoStream(false);

See details in API Manual about stopLocalVideoStream.

  1. Disable publishing local video:
ThunderEngine.stopLocalVideoStream(true);
ThunderEngine.stopVideoPreview();

See details in API Manual about stopLocalVideoStream and stopVideoPreview.

During local publishing, you can set publishing parameters:

ThunderEngine.setVideoEncoderConfig(ThunderVideoEncoderConfiguration yyVideoConfig);

See details in API Manual about setVideoEncoderConfig.

3.5 Receive and Display Remote Videos

If another user begins publishing in your room, you will receive event callback of onRemoteVideoStopped in the ThunderEventHandler callback:

public void onRemoteVideoStopped(String uid, boolean stop) {}

After receiving this event, the video of the remote user should be rendered:

ThunderVideoCanvas canvas = new ThunderVideoCanvas(ThunderPlayerView view, int renderMode, String uid);
ThunderEngine.setRemoteVideoCanvas(canvas);

See details in API Manual about setRemoteVideoCanvas.

3.6 Exit a Channel

To end a call, disable the application or switch it to the background, call leaveRoom to exit the current call channel.

int ret = mThunderEngine.leaveRoom();
See details in API Manual about [leaveRoom](/en/product_category/rtc_service/rt_audio_interaction/api/Android/current/function.html#thunderengineleaveroom).

4. API Reference

5. Notices

Pay attention to the following during integration:

  • If no Looper is specified for callback, SDK callback will be implemented in the thread where SDK is created
  • API return value: return 0 for success and return <0 for failure.

Was this page helpful?

Helpful Not helpful
Submitted! Your feedback would help us improve the website.
Feedback
Top
<