Agora Video Call



One of the biggest challenges facing any developer is building applications that can scale. Making a video-conferencing application that can scale is especially challenging because video data is pretty heavy. And as the number of participants rises, it becomes increasingly difficult to make sure that your application can keep up.

In this tutorial, I use Agora to build an application that can scale to up to 17 users by optimizing the bandwidth usage of the video streams.

Documentation

TLDR: You can get the source code for the demo on GitHub.

What does Agora Video Call do? Enjoy high definition video communication anywhere anytime. HD Video Call, Extremely low latency, Quality assurance on all kinds of internet conditions. Implement the basic video call This section introduces how to use the Agora Video SDK to make a call. The following figure shows the API call sequence of a basic one-to-one video call. Once you have integrated the Agora iOS SDK into your project, you need to call the core APIs provided by the Agora iOS SDK in the ViewController file to implement a basic video call. The API call sequence is shown in the following figure: 1. The Real-Time Engagement Platform for meaningful human connections. People engage longer when they see, hear, and interact with each other. With Agora, you can embed vivid voice and video in any application, on any device, anywhere.

Prerequisites

  1. An Agora developer account (see How To Get Started with Agora)
  2. Basic knowledge of Kotlin and Android Development

Project Setup

  1. Open Android Studio, create a project, and select the template as “Empty Activity”:
  1. Give a suitable name for your application and click Finish.
  2. Add the necessary dependencies to your app build.gradle file:
  1. Add the relevant permissions to your manifest:

All done! It’s time to start building the application.

Build

Now we build the application. I’ll show you how to build the UI for the local video and then put all the remote views in a grid layout by using a RecyclerView.

The structure for the Kotlin files is pretty simple:

I’ll discuss the RemoteViewAdapter more later on.

Setting Up the Main Activity

We’ll first do some basic setup of the main activity so that you can see how this activity is structured:

This is a basic skeleton of the project. The App ID should be familiar if you followed the guide I have linked to above. The Channel can be any string. The important bit is that if any client wants to talk to another client, they have to be on the same channel. For the token, you can get a temporary token by following this guide. For production use cases, you need to set up a token server.

The workflow of the application looks like this:

  1. We check if the required permissions are already granted.
  2. If the condition is true, we call the initializeApplication method, which will contain the bulk of our work.
  3. If the condition is false, we request the permissions. Android then brings up the permission overlay.
  4. After the user interacts with it, the onRequestPermissionsResult callback is called. We can then call initializeApplication if the permissions are granted.

Asking for the Relevant Permissions

First, we write the logic for checking if the required permissions are already granted:

We then write the logic for the method that is called when we want to request the permissions:

Finally, we write the logic for the callback that is executed when the user has interacted with the permission overlay:

New york diagnostics interface (com5) driver download. If all the required permissions are granted, we call the initializeApplication method. However, if they are not granted, we call finish to destroy the activity.

Setting Up the Layout

Before we jump into implementing the final method of the application, let’s finish designing the UI. For the sake of simplicity, I’ve kept the UI minimal.

The FrameLayout here is the container into which the SurfaceView for the local video is injected. SurfaceView is where Agora usually renders its streams on Android. The RecyclerView will be used to display a grid of videos of the remote users. The Guideline is used here to divide the percentage of screen real estate used by each component.

Setting Up the RtcEngine

It’s time to start implementing the initializeApplication method. Here we have the core application logic:

We also need to make sure to add the following property to our activity:

So, the first thing we do is create an RtcEngine object by giving it our App ID (which we discussed above and an event handler (which we will discuss soon). We do some basic configuration such as enabling the video and setting parameters like resolution, FPS, bitrate, and orientation. We set up our local video and then join the channel. And we enable dual-stream.

Dual-stream is an Agora feature that allows a client to publish two streams at the same time. One stream is for a higher resolution and bitrate, and the other stream is for a lower resolution and bitrate. With this dual-stream setup, when a remote client subscribes to your stream, they can switch to a lower stream based on their bandwidth requirements.

Call

Now let’s set up the remote videos.

Setting Up the Remote Videos

We will now make a grid layout of videos. We use RecyclerView to do this because we can’t load all the remote users into memory at the same time. Using RecyclerView allows us to lazy-load the required streams.

First, we create our adapter:

We are doing three main things:

  1. Creating the ViewHolder in onCreateViewHolder method
  2. Setting up the remote video in the onBindViewHolder method
  3. Muting the remote video in the onViewRecycled method

Now that we have created our RecyclerView adapter, we can set up the RecyclerView in our initializeApplication method:

We use the GridLayoutManager to get our RecyclerView to use a grid layout. We set the span count to 2 so that we have a total of two rows in the grid. We set the orientation to horizontal.

Now we create an instance of the adapter we just wrote. Make sure to add the following properties to the activity:

We write the contents of the callbacks in the IRtcEngineEventHandler:

Agora Video Call App

Alaska hdc-m driver download. In the onUserJoined callback, we are doing the following:

  • Muting the remote video stream.
  • Adding the UID of the remote video to a list of UIDs that we use as the dataset of the RecyclerView. We need to make sure that the data is not accessed by multiple threads at the same time, so we use a mutex to maintain a lock.
  • Checking if the number of remote users has grown to four to know whether to switch to using the lower stream in dual-stream mode.
  • Notifying the RecyclerView adapter that a new item is added.

In the onUserOffline callback, we are doing the following:

  • Getting the index of the UID to remove and then removing the UID from the list of UIDs that we are maintaining.
  • Removing the remote video stream from being rendered into the SurfaceView.
  • Switching back to the higher stream in the dual-stream mode if the number of remote users shrinks to three.
  • Notifying our RecyclerView adapter to remove the item.

We need to add the following properties to our activity:

Cleaning up

Finally, it is time to write the onDestroy method. We clean up all the resources relevant to Agora here:

There you go! You should now have everything necessary to run the application.

Testing

Before you build the app, make sure you did the following:

  • You added your App ID to the APP_ID variable.
  • You added your channel name to CHANNEL.
  • If your project has App Certificate enabled, you used your token in the TOKEN variable.
  • You followed all the instructions correctly, like adding the correct dependencies to the build.gradle, adding the permissions to your manifest, and so on.

After you build the app, you should see something like this:

Done!

Congratulations! You have learned how to make an application that has all the necessary optimizations to have scalable video-conferencing capabilities.

You can get the entire codebase from this repository.

If you want to test the app with a web client, you can use the following hosted demo, which has dual-stream enabled: demo

Other Resources

For more information about Agora applications, take a look at the Agora Video Call Quickstart Guide and Agora API Reference.

To learn more about dual-stream, you can take a look at our guide on stream fallback.

I also invite you to join the Agora Developer Slack community.

Want to build Real-Time Engagement apps?

If you have questions, please call us at 408-879-5885. We’d be happy to help you add voice or video chat, streaming and messaging into your apps.

Stay inspired by accessing all RTE2020 session recordings. Gain access to innovative Real-Time-Engagement content and start innovating today.

Categories

product

Agora’s Voice SDK provides crystal-clear voice chat for your web, mobile and native apps.

USE CASES

Personalize conversations with live voice calls.

Live conversations improve in-app engagements, enhancing the fun and personalizing remote work.

Agora’s Voice Call lets you integrate high-quality, stutter-free interactive voice chat into your app and makes it easy for you to add new features like voice effects and 360-degree surround sound, noise cancellation, and active-speaker recognition.

Features

Agora’s Voice Call provides reliable, high-quality, real-time voice capabilities that you can customize for your application.

Outstanding audio

Clear audio

The Agora Voice Call SDK uses a 48 kHz sampling rate with full-sound bandwidth capture. It provides natural audio reproduction and ensures clear sound when it matters most. Agora’s Real-Time Engagement Platform provides HD audio up to 192kbps (hardware limitations apply) supported by our in-house SOLO™ and NOVA™ audio codecs.

Background and surround sound

Include local background music, accompaniment, and sound effects along with voice for a more immersive user experience.

Seamless audio

Agora’s proprietary algorithms ensure consistent audio, free of stutters and jitters, even under challenging network conditions that may have up to 80% packet loss.

AI-powered noise cancellation

Using automatic echo cancellation, automatic gain control, automatic noise suppression, and an AI-powered noise cancellation algorithm, Agora’s platform adapts to variant acoustic conditions to remove ambient and distracting noises, ensuring voices come through crystal clear.

Creative possibilities

Voice effects

Make in-app calls fun and engaging using a variety of voice APIs that can add a range of special effects. From sound mixing to sound reverb, users can change the way their voices sound to match their moods, characters they’re playing, or just satisfy a whim.

Surround sound

Agora expands the traditional left and right stereo channels to deliver an enveloping 360 degrees of sound. Users can adjust the positioning and distance of the channel to create more immersive gaming, virtual-reality, or augmented-reality experiences.

Versatile controls

In-ear monitoring

Agora’s Real-Time Engagement Platform supports in-ear monitoring for mobile devices. Users can hear their own voices or voice effects in online KTV, live-streaming apps, and other apps where audio is important.

Active-speaker recognition

Agora’s AI algorithms analyze streaming data to identify and capture the active speaker.

Original streams processing

Export the original audio and video streams to process for other purposes.

Recording

Record live audio events on the cloud or on your premises. You control the audio format, path of storage, and voice quality. T100 scanner driver.

Why Agora

You get all the above plus the power of Agora’s Real-Time Engagement Platform

With an intelligent global network, optimizations for mobile devices, cross-platform SDKs, and developer-centric building blocks, why would you choose anyone else?

Developers

Agora Lab Inc

Made for developers

It only takes a few lines of code to connect to the Agora platform.
See the full list of supported platforms on our SDK downloads page.

Pricing that scales with your business

Get 10,000 minutes FREE every month