Welcome toTencent Cloud + community, get more Tencent mass technology practice dry goods oh ~

This article is published in cloud + community column by Tencent Cloud Video

The author of this article, ericxwli, senior engineer, from Tencent cloud terminal team

background

Has recently been boss assigned a task, he opened the WeChat video chat, a multiplayer video, pointing to the function interface, said “do you think our products also have many conference scene, we also add such a function, also need not complicated, just like WeChat or QQ people do a video, real-time video calls, this should also not bad, Give you a week to fix it, ok?” My heart in think this TM involves video collection, coding, transmission, decoding and video rendering, want to have a stable background audio and video transmission, will light up the background will survive, the nima how make, eldest brother again fill 1 he left, “oh, we are here to add a bright spot, can send text messages in the video interface, expand the chat”, By this time I was falling apart inside.

A week, will have to see if there are any ready-made solutions, try holding the attitude of Google, unexpectedly also has a real, tencent, sound structure, netease cloud, cloud network etc. Several companies to provide a complete solution, in line with tencent, after all, giant and introduce their solution is based on QQ for more than ten years of technology accumulation, Stability and quality are guaranteed, so directly tested tencent cloud solutions, look from the access process and the final effect does not live up to my expectations, when you haven’t really buy their products, access to the problems in the process can be a positive technical support, and let me unexpected is, the scheme also supports im function Solved the boss’s final god repair sword function.

Based on the access process, this paper introduces the specific steps, which can be summarized into four steps:

First, register an account

Enter the website

Register their own Tencent cloud account, this simple nothing to say, Tencent cloud also provides QQ or wechat account direct login, save the trouble of registration.

Apply for an APPID

Before accessing real-time audio and video in Tencent Cloud, we need to register a unique appID for our application. The method is as follows:

Log in to Tencent Cloud, click to enter the console,

Choose Cloud Products -> Live Audio and Video -> Create a new application

Fill in the information and click OK to generate your own AppID, which will be used when accessing SDK later.

Click to create an application and you can manage your application in the console

Three, buy 1 yuan package

Use the application in the appid access real-time audio and video service, duration, tencent will billing according to the length of cloud, as we call billing, tencent cloud here provides some package, we can use the cheapest 1 yuan package, 10000 minutes a month, also meet commonly use, if feel effect is good, We can upgrade the package and buy the entrance when it’s longer

Iv. SDK access

After completing the above preparations, it is the most critical SDK access. The SDK access of Tencent Cloud has special documentation, which is very convenient, mainly including the following key steps:

1. Integrate the SDK

Tencent real-time audio and video solutions will be the underlying audio and video capabilities packaged into a set of SDK sets, including

SDK instructions
IMSDK Provides the IM instant messaging function
AVSDK Provides underlying audio and video functions
ILiveSDK Packaged on the basis of AVSDK, it provides a more simple audio and video interface
BeautySDK Provide beauty pretreatment function

We just need to download the last SDK and import it into our own project. For details, please read the official access document

2. Generate usersig

Each user has a user ID. The userSIG is an encryption string used for authentication and authentication of the user ID. The generation procedure is as follows:

The first step is to download the private key from the console of Tencent Cloud, which is this one

** Step 2, copy the private key

Download A keys.zip file, open it with Winrar, right click private_key, and press Ctrl+A, Ctrl+C to copy **

** Step 3, generate userSig

Still in the console of Tencent Cloud, find [Development assistance] on the left, input the user name, Ctrl+V here in the private key, click [Generate signature], and then you can copy down the generated userSig on the right **

3. Initialize the login

Call the interface where the program starts:

// Initialize the iLiveSDK
ILiveSDK.getInstance().initSdk(this, Constants.SDKAPPID, Constants.ACCOUNTTYPE);
// Initialize the iLiveSDK room management module
ILiveRoomManager.getInstance().init(new ILiveRoomConfig()
          .setRoomMsgListener(this));
Copy the code

SdkAPPID is the APPID just applied, and acountType is in the application account information

After the initialization, use userID and usersig to log in

ILiveLoginManager.getInstance().iLiveLogin(userId, userSig, callback);
Copy the code

4. Enter the room, video rendering

Controls for layout rendering:

` ``Java

Copy the code

<com.tencent.ilivesdk.view.AVRootView


    android:id="@+id/av_root_view"

    android:layout_width="match_parent"

    android:layout_height="match_parent" />


Copy the code

And set to SDK:

ILiveRoomManager.getInstance().initAvRootView(avRootView);
Copy the code

There are two ways to enter a room, the room does not exist, call the Create room interface

ILiveRoomManager.getInstance().createRoom(roomId, new ILiveRoomOption(), callback);
Copy the code

If the room already exists, the Join room interface is called:

ILiveRoomManager.getInstance().createRoom(roomId, new ILiveRoomOption(), callback);
Copy the code

A roomID is a room number that is maintained by its own service.

After entering the room, for this application is into the conference room, will automatically enter the conference room each person picture rendering.

5. Message processing

In the last of a boss, you need to add the text messaging function in video call, the boss said, more simple but a message chat only the establishment of the news channel is a very difficult thing, but in the process of access to surprise tencent real-time audio and video itself provides this functionality, real get whole don’t bother, And it is very simple to start the chat function, just need to turn on the imSupport of ILiveRoomOption when entering the room, and then set message monitoring to receive messages, message sending is also an excuse for S to call, the code is as follows:

// Message sent
ILiveMessage message = new ILiveTextMessage(test);
ILiveRoomManager.getInstance().sendGroupMessage(message, callback);
Copy the code

## Effect display

Waves in waves, originally thought that the task is certainly not complete, did not expect less than a day has built a video call function. The above is the main steps of building video call service from zero based on Tencent cloud official document guide, taking Android as an example. If you have any other problems, please leave a message.

** Q&A ** How to use applets to make video calls?

reading

【 small video 】 special effects recording plug-in strong attack

After 3, 000 short videos, I finally discovered the 3 million likes pattern of Internet celebrities

How can instant messaging apps take off? The technical principle behind it can be cut from these 5 angles

Machine learning in action! Quick introduction to online advertising business and CTR knowledge

This article has been authorized by the author to Tencent Cloud + community, more original text pleaseClick on the

Search concern public number “cloud plus community”, the first time to obtain technical dry goods, after concern reply 1024 send you a technical course gift package!

Massive technical practice experience, all in the cloud plus community!