Video Call Android Tutorial – Implementing Video Call using Sinch

In the field of smartphones, video calling feature is yet another breakthrough and it turned out to be a pretty cool feature. Getting to see the person live you are talking to is really a …

video call android tutorial

In the field of smartphones, video calling feature is yet another breakthrough and it turned out to be a pretty cool feature. Getting to see the person live you are talking to is really a great step towards narrowing the communication gap among people. Today, we have a large number of apps in play store which provide the video call utility such as Imo, Google Duo, WhatsApp, Messenger and the list goes on. So here I have a detailed Video Call Android Tutorial for you.

If your are reading this, that means you wish to implement this cool utility in your android application. Well, if you just think for a while as a developer of creating a complete workflow for a mobile video call facility, you would begin with something like this. First, you need to send the video feed of the phone’s camera to the server and that too in realtime. Now that requires you select a proper protocol to do so. Then receiving the data from the server on the other phone. After thinking all of this, you end up having no clue of how to get started with this exactly.

Well, what if I tell you that you could implement this utility in your app without giving a damn about the data transmission, server and anything else for that matter. Yes, with a  SDK called Sinch, it is very much possible. All you need to do is import the SDK in your project and  you’ll be good to go.

Now that we are done with the overview, we shall directly start working on the project for our Video Call Android Tutorial.

Video Call Android Tutorial

Registering your App on Sinch

Go to  the Sinch website and  scroll down the homepage to see the screen below.

video call android tutorial

Select video on the above screen and you shall see the screen below

video call android tutorial

Click on GET STARTED button to move ahead and you shall see this register page down below.

video call android tutorial

Quickly fill in details and register to see the welcome page as shown below.

video call android tutorial

Here, you need to verify your phone number and it shall grant you a credit of 2$ for free. So go ahead and quickly verify your mobile number.

Once the verification is done, you shall see a welcome page saying you’re all set as shown below.

video call android tutorial

Hit  the Get Started button to go further and you’ll see this page asking for your app’s name and description.

video call android tutorial

Fill in the required details and hit Create and you shall see a page asking you to choose from available services as shown below.

video call android tutorial

Select Video Calling in the above screen and you shall be asked to select the development platform in the screen below.

video call android tutorial

Choose Android in the above screen and you’ll  be shown something like below:-

video call android tutorial

  • In the above screen you can see the three unique keys have been assigned to your app. Copy them somewhere as you’re gonna need these in this app.
  • Hit the Download Android SDK button and wait for it to be downloaded.

Creating a new project

  • Begin with creating a new project in Android Studio.

Importing Sinch SDK into your project

  • Unzip the downloaded file and go to the following directory-:
  • sinch-android-rtc-3.8.0-VIDEO-20151119.112353-6\sinch-android-rtc-3.8.0-VIDEO-SNAPSHOT\libs
  • You shall see something like below

video call android tutorial

  • Now copy the jar file from the above directory.
  • Go to this  directory  YourAppName/app/libs  in your project and paste the jar file in the libs folder.
  • RightClick on the jar file and click on Add as Library and wait for the Gradle to be synced.
  • Now, go to the folder from where you copied the jar file and this time copy the two folders by the name armeabia-v7a and x86.
  • Next, in the following directory YourAppName/app/src/main of your project, create a new directory  by the name jniLibs in the main folder.
  • Paste the two folders that your previously copied in the jniLibs folder

And you have successfully imported the Sinch SDK in your project and you’re good to code.

Understanding the workflow of this app:-

  1. In an activity called LoginActivity, a user enters a unique username and logs in.
  2. In the next Activity called PlaceCallActivity, the user enters the name of the another  user to whom the call is to be placed. Mind it that the other user must remain logged in order to receive the call.
  3. If the user on the other end is found to be logged in. He/She shall recieve the video call.
  4. Once the call is answered, the users on both the ends would be sharing their camera feeds.

Coding the App

Before coding the activities, there are certain classes used by the all the activities.

They are as follows:

  • SinchService.java
  • BaseActivity.java
  • AudioPlayer.java

Begin with SinchService.java. Create new class named SinchService.java and add the following code to it:-

This class is responsible to create a session for your app on the server each time you try to use it.

Hop over to the top  of this class and you’ll notice the following three constants:-

Replace the values of these constants with the ones that you got after the registration of this app on the Sinch website

  • Next, create a class named BaseActivity.java and add the following code to it:-
  • This class is extended by all the activities which enables them to bind the SinchService to themselves.

Next on the list is AudioPlayer.java. So, create  a new class named AudioPlayer.java and add the following code:-

This class manages the audios to be played to notify the user of the incoming video call.

Coding the screens

The Login Screen

The first page of this app would be the Login Screen. So go ahead and create a new layout resource file by the name

login.xml and add the following code to it:-

The above code would generate the following layout

Next, let’s set the backend of this screen. To do so, create a class named LoginActivity.java and add the following code.

The above code has been commented to help you understand the codeflow.

The PlaceCall Screen

Next is the PlaceCallActivity where you enter the name of the user to whom the call is to be placed.

To create the UI for the screen, create a new layout resource file by the name main.xml and add the following code.

The above code shall generate the following layout

video call android tutorial

 

Now that the UI is set up, we need to configure the Java part for this activity. To do so, create a class named PlaceActivity.java and add the following code:-

In the above code, the following things have been taken care of:-

  • Setting up the connection to the Sinch Service.
  • Configuring controls to place the call

The CallScreen

Now, we need to set up the activity in which the actual call would be placed. To do so, create a new layout resource file named callscreen.xml and add the following code.

The above code would generate the following layout

video call android tutorial

Java Part- Create a class named CallScreenActivity.java and add the following code:-

The Incoming Call  Screen

Now that the CallScreenActivity has been  configured, it’s time to configure the Incoming CallScreenActivity.

To do so, create a new layout resource file named incmoing.xml and add the following code:-

The above code would generate the following  layout.

video call android tutorial

Next, create a class named IncomingCallScreenActivity.java  and add the following code:-

The above code is quite self explanatory.

Setting up resources

Now that the screens are all set. We need to set up the audios to played when call is placed and received.
To do so, in the res directory of your project, create new directory of the name raw.

Download the zip of audios from the link given below and paste these into the raw directory.

[download id=”4353″]

Finalizing project

We are almost done. Just update your AndroidManifest.xml  file as shown   below:-

That’s it. Your app is ready to be tested. Just login with  unique usernames on two mobile phones. and in  the recipients name, enter one of the usernames, hit the call button and you shall see the other phone ringing.

So thats all for this Video Call Android Tutorial, you can also get the source code of my project from the link given below.

[sociallocker id=1372] Video Call Android Tutorial [/sociallocker]

Feel free to clarify your doubts in the comments section if you come across any regarding this Video Call Android Tutorial. Thank You 🙂

Hello, I am Manish Kumar. I am a B.Tech Student at NIT Jamshedpur. Fortunately, I find myself quite passionate about Computers and Technology. Android is my most recent Crush.

Expand Your Knowledge: Next Tutorial Picks

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x