How Android audio and video instant messaging software can be quickly implemented with JNI

Source: Internet
Author: User

How Android audio and video instant messaging software can be quickly implemented with JNI

Audio and Video communication

As an independent developer or a company that wants to shorten the audio and video development cycle, you want toAndroidThe quickest way to achieve audio and video communication under the platform is to find open source projects or call other companiesAPI。 The reason for this is that the audio and video communication technology involves the underlying audio and video acquisition, decoding,FFmpeg(Audio and video processing solutions), media streaming protocol and so on too many related technical knowledge points. Tried several open source projects, video passable, voice and video out of sync, and other unstable factors. So I put my eyes on the other companies.APIOn( Click to download demo program )。DemoProgramAPIProvides a range of pureJavaThe language of the calling interface, throughJNIYou can call the kernel shared library (. soSimilarWin32OfDLL), according to the official development document I soon realized the audio and video communication, the following is I call itsAPISummary of the experience. The video is as follows:

650) this.width=650; "alt=" Picture "src=" http://b230.photo.store.qq.com/psb?/v13lkchu2om1rt/i31qphoa*dtgqrozwnufkn* ukv4czxzcimcr2x8ryvy!/b/de9kgon4fqaa&ek=1&kp=1&pt=0&bo=ianxagaaaaadafm!&su=098329265& Sce=0-12-12&rf=2-9 "style=" margin:0px;padding:0px;border-width:0px;border-style:none;vertical-align:top; width:800px;height:599px; "/>

Android Communication Platform related API Method

650) this.width=650; "alt=" Picture "src=" http://b268.photo.store.qq.com/psb?/V13LKChu2oM1rt/ 7cpabqpglnsl1s0pwyjp6cglyq6s31sdjxrsvk3m8eu!/b/dodmzj*6dgaa&ek=1&kp=1&pt=0&bo=1akpaqaaaaadah0! &su=0105813089&sce=0-12-12&rf=2-9 "style=" Margin:0px;padding:0px;border-width:0px;border-style:none ; vertical-align:top;width:724px;height:399px; "/>

first, the initialization of SDK

Initialize SDK is the first thing to do, to set SDK Some of the behaviors, including setting the corresponding callback function. The code is as follows:

650) this.width=650; "alt=" Picture "src=" http://b231.photo.store.qq.com/psb?/V13LKChu2oM1rt/ mvoeuc9saaoyvnq93cgstkvnfy3rlt796aww5ramsam!/b/dmd8uik7fgaa&ek=1&kp=1&pt=0&bo=wwldaaaaaaadadk! &su=0249789409&sce=0-12-12&rf=2-9 "style=" Margin:0px;padding:0px;border-width:0px;border-style:none ; vertical-align:top;width:707px;height:221px; "/>

Second, login system

when initializing SDK When you are finished, you can connect to the server, authenticate the user, log in, and so on.

650) this.width=650; "alt=" Picture "src=" http://b266.photo.store.qq.com/psb?/V13LKChu2oM1rt/ qogzydmzegz85riiaq3tlklflvpmvuycsph87gl2fkm!/b/ddcump6kfgaa&ek=1&kp=1&pt=0&bo=qgfhaaaaaaadamk! &su=083642529&sce=0-12-12&rf=2-9 "style=" margin:0px;padding:0px;border-width:0px;border-style:none; vertical-align:top;width:426px;height:71px; "/>

Both the connection server and the logon system are asynchronous processes that return immediately after the call. In the callback function, according to the return code to determine whether the server connection success and logon success.

Third, enter the room

After the successful login can enter the corresponding room, only in the same room users can do audio and video communication. The code is as follows

1 , enter the room

650) this.width=650; "alt=" Picture "src=" http://b268.photo.store.qq.com/psb?/V13LKChu2oM1rt/ of39jsxcndowjbg69ncyih2gwltg4u9ae8l6vlug8c8!/b/dnbxxp*3dgaa&ek=1&kp=1&pt=0&bo=vaepaaaaaaadafk! &su=0160788273&sce=0-12-12&rf=2-9 "style=" Margin:0px;padding:0px;border-width:0px;border-style:none ; vertical-align:top;width:340px;height:41px; "/>

After entering the room, the system will send the room online users to the client, only in the same room users can do audio and video exchange, text chat, file transfer and so on. When a new user enters a room or a user goes offline, an asynchronous message is triggered to notify the upper-level app to change state.

2 , text chat

Once you have successfully entered the room, you can call API interface sends text to the specified user or to all online users in the room chat messages.

650) this.width=650; "alt=" Picture "src=" http://b231.photo.store.qq.com/psb?/V13LKChu2oM1rt/ Leroawaboggi81ta4qhztoy5dkrbgamwhwtglpay84e!/b/dcgqv4ncfqaa&ek=1&kp=1&pt=0&bo=8ge8aaaaaaadaoo! &su=0244161201&sce=0-12-12&rf=2-9 "style=" Margin:0px;padding:0px;border-width:0px;border-style:none ; vertical-align:top;width:498px;height:60px; "/>

Other users receive a text chat message that triggers the corresponding callback function and displays the chat message on the interface.

3 , requesting audio and video from other users

650) this.width=650; "alt=" Picture "src=" http://b265.photo.store.qq.com/psb?/V13LKChu2oM1rt/ z0ckflbyte4fcyq2r8i92spjfymodxkffqmyjjkz.xi!/b/dnd1.z2tkaaa&ek=1&kp=1&pt=0&bo=jqfiaaaaaaadaoe! &su=0239993105&sce=0-12-12&rf=2-9 "style=" Margin:0px;padding:0px;border-width:0px;border-style:none ; vertical-align:top;width:397px;height:72px; "/>

4 , audio and video display and playback

650) this.width=650; "alt=" Picture "src=" http://b265.photo.store.qq.com/psb?/v13lkchu2om1rt/afcxhk19y4tag0lhte* idu3yhrvh2mqwp7pnc.gwuxo!/b/dhb4.z2lkaaa&ek=1&kp=1&pt=0&bo=xwksaqaaaaadahm!&su=0182693793 &sce=0-12-12&rf=2-9 "style=" Margin:0px;padding:0px;border-width:0px;border-style:none;vertical-align: top;width:711px;height:402px; "/>

Android program, when a user's media stream data is received, Android The client simply provides a Surfaceview control, the kernel automatically displays the video stream data on the control and plays the sound.

Iv. release of resources

With the previous connection server, login system, enter the room corresponding to the departure room, logout system, release resources. The code is as follows:

650) this.width=650; "alt=" Picture "src=" http://b230.photo.store.qq.com/psb?/v13lkchu2om1rt/gkufpxti* i2s3pfzo3cubaapwlxux2musl*lhmpjx2e!/b/dgr3i4n9fqaa&ek=1&kp=1&pt=0&bo=awkdaaaaaaadakc!&su= 0187474961&sce=0-12-12&rf=2-9 "style=" margin:0px;padding:0px;border-width:0px;border-style:none; vertical-align:top;width:515px;height:131px; "/>

After leaving the room, you can enter the room again, but after logging off and releasing the resources, SDK will no longer work. The resource can be freed at the end of the Activity life cycle and the program exits.

Summary: This is the application of the Anychat IM SDK, as well as other issues such as sending files, Peer connections, the Android device settings, access to online users and other very useful features. With Java We can also quickly achieve audio and video communication.



How Android audio and video instant messaging software can be quickly implemented with JNI

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.