Basic: Making a Video Call

Basic: Making a Video Call

Getting Started

Step 1: Prepare the Environment

  1. Download the Video SDK.
  2. Hardware and software requirements:
    • Android 4.1 and later devices with audio and video support
    • Android SDK API 16 or later
    • Android Studio 2.0 or later

Step 2: Add the SDK

  1. Copy the following libraries from the libs folder according to your needs.

    • agora-rtc-sdk.jar (mandatory)
    • armeabi-v7a/
    • x86/
    • arm64-v8a
    • include

    Note

    When copying the libraries to the libs folder in the targeted path, if there is any Chinese character in the path, the sample code will not be compiled successfully, and will display random ASCII code in the error message.

  2. Put the required libraries in the correct libs path according to the settings in the build.gradle file.

    ../_images/android_library.png
  3. Specify the directory of the so file in the build.gradle file as the path of the libs folder in step 2.

    ../_images/android_so.png

Step 3: Configure the NDK

If the following error displays, it means that the NDK is not installed.

../_images/android6.png

Download the NDK from the Android developer website, and put it in the Android location, for example,

../_images/android7.png

Step 4: Add the Permissions

The following permissions are required in the AndroidManifest.xml file for your application when deployed:

  • <uses-permission android:name=”android.permission.INTERNET” />
  • <uses-permission android:name=”android.permission.RECORD_AUDIO” />
  • <uses-permission android:name=”android.permission.CAMERA” />
  • <uses-permission android:name=”android.permission.MODIFY_AUDIO_SETTINGS” />
  • <uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” />

Step 5: Synchronize with the Project Files

Click Sync Project With Gradle Files until the synchronization is complete.

../_images/android9.png

Step 6: Obfuscate the Code

Add the following line to obfuscate the code:

-keep class io.agora.**{*;}

Scenario 1: Making a Video Call

  1. Get an App ID, refer to Getting an App ID.
  2. Initialize RtcEngine, and fill in the App ID, refer to Create an RtcEngine Object (create).
private void initializeAgoraEngine() {
    try {
        mRtcEngine = RtcEngine.create(getBaseContext(), getString(R.string.agora_app_id), mRtcEventHandler);
    } catch (Exception e) {
        Log.e(LOG_TAG, Log.getStackTraceString(e));

        throw new RuntimeException("NEED TO check rtc sdk init fatal error\n" + Log.getStackTraceString(e));
    }
}
  1. Set the video profile, refer to Set the Video Profile (setVideoProfile).
private void setupVideoProfile() {
    mRtcEngine.enableVideo();
    mRtcEngine.setVideoProfile(Constants.VIDEO_PROFILE_360P, false);
}
  1. Set the local video, refer to Set the Local Video View (setupLocalVideo).
private void setupLocalVideo() {
    FrameLayout container = (FrameLayout) findViewById(R.id.local_video_view_container);
    SurfaceView surfaceView = RtcEngine.CreateRendererView(getBaseContext());
    surfaceView.setZOrderMediaOverlay(true);
    container.addView(surfaceView);
    mRtcEngine.setupLocalVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_ADAPTIVE, 0));
}
  1. Join a channel, refer to Join a Channel (joinChannel).
private void joinChannel() {
    mRtcEngine.joinChannel(null, "demoChannel1", "Extra Optional Data", 0); // if you do not specify the uid, Agora will assign one.
}
  1. Set the remote video, refer to Set the Remote Video View (setupRemoteVideo).
private void setupRemoteVideo(int uid) {
    FrameLayout container = (FrameLayout) findViewById(R.id.remote_video_view_container);

    if (container.getChildCount() >= 1) {
        return;
    }

    SurfaceView surfaceView = RtcEngine.CreateRendererView(getBaseContext());
    container.addView(surfaceView);
    mRtcEngine.setupRemoteVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_ADAPTIVE, uid));

    surfaceView.setTag(uid);
    View tipMsg = findViewById(R.id.quick_tips_when_use_agora_sdk);
    tipMsg.setVisibility(View.GONE);
}
  1. Hang up/End a call, refer to communication_android_leavechannel_en.
private void leaveChannel() {
    mRtcEngine.leaveChannel();
}

The following APIs are related to making your first video call:

Note

After joining a channel, the SDK turns on the camera by default, and you can call Start a Video Preview (startPreview) to enable the preview function. You can also call Disable the Video Mode (disableVideo) to switch to voice-only mode.

You can now start a one-to-one or group video call. The difference between a one-to-one and group call is the number of people joining the channel.

Scenario 2: Implement other Functions

The following functions can be implemented in a voice call:

Agora will provide the API call sequences and sample code for the following functions in the future. For now, see Video Call API:

  • Voice and video conference
  • Image control
  • Send text messages
  • Capture video data