Audio-Visual interactive development platform for Android platform

Source: Internet
Author: User

    • Compatible with mainstream hardware devices such as Google, HTC, Xiaomi, Samsung, Huawei, etc.

    • Enables interoperability between devices such as iOS, Web, PC, and Android

    • Video session, the front camera is turned on by default;

    • Can have Java audio and video capture, display driver, compatible with more Android devices;

    • to achieve audio and video communication under the Android platform, the quickest way is to find an open source project or call another company packaged API, the next small to introduce a good SDK package to everyone, (Audio and video interactive development platform for Android platform) Here are some ways to call the relevant API interface, you can communicate with each other.


Android communication platform related API methods

    //  Initialize sdk      public native int  INITSDK (int osver, int flags);      //  connection Server        public native int connect (String serverip, int port);       //  Login System       public native  Int login (String username, string password);      //  Enter room (room ID)       public native int enterroom (int roomid,  string password);      //  Enter the room (room name)        public native int enterroomex (String roomname, string password);       //  Exit Room       public native  Int leaveroom (int roomid);       //  Setting video display location       public native  Int setvideopos (int userid, surface surface, int lef,               int top, int right, int  Bottom);      /**       *  function:  Set the video display location, or refresh the video display   return value: 0 indicates success, otherwise error code         *  parameter:         * userid   User id         * surface  video Display interface, Android client only needs to provide Surfaceview control, the kernel automatically displays the video on the control         * lef,top,right,bottom Video Display location information        */      //  Logout Login       public native int logout ();       //  Release Resources       public native int release (); 
first, the initialization of the SDK

Initializing the SDK is the first thing you need to do to set up some behavior for the SDK, including setting the corresponding callback function. The code is as follows:

    //Initialize SDK      PRIVATE VOID INITIALSDK ()  {           if  (anychat == null)  {               anychat = new  ANYCHATCORESDK ();               // Sets the basic event callback function               anychat. Setbaseevent (this);               if   (configentity.usearmv6lib != 0)                    anychat. Setsdkoptionint (anychatdefine.                           brac_so_coresdk_USEARMV6LIB, 1);             //use ARMV6 instruction set               anychat. INITSDK (android.os.build.version.sdk_int, 0);    //initialization sdk  One parameter is ANDROID API version               bNeedRelease =  true;          }      }
Second, login system

After the initialization of the SDK is complete, it can be implemented to connect the server, verify user identity, user login and so on.

Connect the server Anychat.          Connect ("211.155.25.90", 8906); Log in to the system anychat. Login ("Android", "");

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

Enter Room 1th, Anychat. Enterroom (1, "");

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 the API interface to send a text chat message to the specified user or to all online users in the room.

Send a text chat message String message = Messageedittext.gettext (). toString (); Anychat. Sendtextmessage ( -1, 0,message);

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

3. Request audio and video from other users

Request the other person's video stream anychat.          Usercameracontrol (UserID, 1); Request the other's audio stream anychat. Userspeakcontrol (UserID, 1);

       //determine if the remote user video is turned on            if  (!bothervideoopened)  {               if  (Anychat. Getcamerastate (UserID)  == 2                      && anychat. Getuservideowidth (UserID)  != 0)  {                   surfaceholder holder = otherview.getholder ();    //Get Surfaceview Controls                    holder.setformat (pixelformat.rgb_565);           //Setting display format                     holder.setfixedsize (Anychat. Getuservideowidth (UserID),                           anychat. Getuservideoheight (UserID))     //set video display width                    surface s = holder.getsurface ();                 //get video footage                    anychat. Setvideopos (userid, s, 0, 0, 0, 0);      //Invoke API Display video screen                     bothervideoopened = true;               }          }           //determine if the local video is turned on           if  (! bselfvideoopened)  {              if   (Anychat. Getcamerastate ( -1)  == 2                      && anychat. Getuservideowidth ( -1)  != 0)  {                   surfaceholder holder = myview.getholder ();       //Get Surfaceview Controls                    holder.setformat (pixelformat.rgb_565);           //Setting display format                    Holder.setfixedsize (Anychat. Getuservideowidth ( -1),                           anychat. Getuservideoheight ( -1))         //set video display width                    surface s =  holder.getsurface ();                 //Get video footage                    anychat. Setvideopos ( -1, s, 0, 0, 0, 0);          Call API to display video screen                    bselfvideoopened = true;               }          }

Android program, when receiving the user's media stream data, the Android client only need to provide 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:

protected void OnDestroy () {//Leave room anychat.      Leaveroom (-1); Log off the login anychat.      Logout (); Releasing resources off the SDK no longer returns to the login interface Anychat. Release (); }

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


Audio-Visual interactive development platform for Android platform

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.