Development of audio and video instant messaging applications on iOS platform

Source: Internet
Author: User

Development of audio and video instant messaging applications on iOS platform
Now IOS is very popular. A lot of developers are developing IOS platforms. I believe you have also used QQ's voice/video conversation function, but I don't know if you have tried to develop an IOS-based real-time audio and video communication application. This application must be cross-platform.

  • Supports the development of audio instant messaging applications on iOS devices
  • Provides Objective-C language API and open sample source code.
  • Integrate H.264, AAC, AMR, and other coding and decoding Technologies
  • Encapsulation of audio and video collection, encoding/decoding, transmission, display, and playback modules
  • Supports interconnection between devices such as Android, Web, and PC and iOS
  • The quickest way to implement Audio/Video Communication on IOS is to find open-source projects or call APIs encapsulated by other companies.


    Next, I will introduce a good SDK package for you, AnyChat SDK. This is a cross-platform real-time audio and video communication solution. The following describes how to call related API interfaces, you can communicate with each other.

    1. // initialize SDK 2.Public Native IntInitSDK (IntOsver,IntFlags); 3. // connect to the server 4.Public Native IntConnect (String serverip,IntPort); 5. // log on to the system 6.Public Native IntLogin (String username, String password); 7. // enter the room (room ID) 8.Public Native IntEnterRoom (IntRoomid, String password); 9. // enter the room (room name) 10.Public Native IntEnterRoomEx (String roomname, String password); 11. // exit room 12.Public Native IntLeaveRoom (IntRoomid); 13. // set the video display position 14.Public Native IntSetVideoPos (IntUserid, Surface surface,IntLef, 15.IntTop,IntRight,IntBottom); 16. /** 17. * function: Set the video display position, or refresh the video display returned value: 0 indicates that the video is successfully displayed. Otherwise, error code 18 is displayed. * parameter: 19. * userid ID 20. * The surface video display interface. The android client only needs to provide the SurfaceView control, and the kernel automatically displays the video on the Control 21. * lef, top, right, and bottom video location information 22. */23. // log out 24.Public Native IntLogout (); 25. // release resource 26.Public Native IntRelease (); 1. initialize the SDK to initialize the SDK. It is used to set SDK behaviors, including setting the corresponding callback function. The Code is as follows: 1. // initialize SDK 2.Private VoidInitialSDK () {3.If(Anychat =Null) {4. anychat =NewAnyChatCoreSDK (); 5. // set the basic Event Callback Function 6. anychat. SetBaseEvent (This); 7.If(ConfigEntity. useARMv6Lib! = 0) 8. anychat. setSDKOptionInt (AnyChatDefine. 9. BRAC_SO_CORESDK_USEARMV6LIB, 1); // use ARMv6 instruction set 10. anychat. initSDK (android. OS. build. VERSION. SDK_INT, 0); // a parameter for SDK Initialization is android API version 11. bNeedRelease =True; 12.} 13.} 2. After the SDK Initialization is complete, you can connect to the server, verify the user identity, and log on to the user. 1. // connect to the server 2. anychat. connect ("211.155.25.90", 8906); 3. // log on to the system. 4. anychat. login ("android", ""); connecting to the server and logging on to the system is an asynchronous process, and will return immediately after the call. In the callback function, determine whether the server is successfully connected and successfully logged on based on the returned code. 3. After logging on to the room, you can enter the corresponding room. Only users in the same room can perform audio/video communication. The Code is as follows 1. Enter the room 1. // enter room 1 2. anychat. enterRoom (1, ""); after entering the room, the system will send the online users of the room to the client. Only users in the same room can exchange audio and video, chat, and file transmission. When a new user enters the room or goes offline, an asynchronous message is triggered to notify the upper-layer application to change the status. 2. After a text chat enters the room, you can call the API to send text chat messages to a specified user or all online users in the room. 1. // send text chat message 2. string message = messageEditText. getText (). toString (); 3. anychat. sendTextMessage (-1, 0, message); when other users receive a text chat message, the corresponding callback function is triggered and the chat message is displayed on the interface. 3. Request audio and video from other users. 1. // request the video stream of the other Party 2. anychat. userCameraControl (userID, 1); 3. // request the audio stream of the other party. 4. anychat. userSpeakControl (userID, 1); 4. Display and play audio and video 1. // determine whether the remote user video is enabled. 2.If(! BOtherVideoOpened) {3.If(Anychat. GetCameraState (userID) = 2 4. & amp; anychat. GetUserVideoWidth (userID )! = 0) {5. surfaceHolder holder = otherView. getHolder (); // obtain the SurfaceView control 6. holder. setFormat (PixelFormat. RGB_565); // set the display format. holder. setFixedSize (anychat. getUserVideoWidth (userID), 8. anychat. getUserVideoHeight (userID); // sets the video display width and height 9. surface s = holder. getSurface (); // obtain the video screen 10. anychat. setVideoPos (userID, s, 0, 0, 0, 0); // call the API to display video screen 11. bOtherVideoOpened =True; 12.} 13.} 14. // determine whether the local video has been enabled.If(! BSelfVideoOpened) {16.If(Anychat. GetCameraState (-1) = 2 17. & anychat. GetUserVideoWidth (-1 )! = 0) {18. surfaceHolder holder = myView. getHolder (); // get SurfaceView control 19. holder. setFormat (PixelFormat. RGB_565); // set the display format 20. holder. setFixedSize (anychat. getUserVideoWidth (-1), 21. anychat. getUserVideoHeight (-1); // set the video display width to 22. surface s = holder. getSurface (); // obtain the video screen 23. anychat. setVideoPos (-1, s, 0, 0, 0, 0); // call the API to display the video screen 24. bSelfVideoOpened =True; 25 .} 26 .} in the Android program, when receiving the user's media stream data, the Android client only needs to provide a SurfaceView control, and the kernel automatically displays the video media stream data on the control and plays the sound. 4. Releasing resources corresponds to leaving the room, canceling the system, and releasing resources when you connect to the server, log on to the system, and enter the room. The Code is as follows: 1.Protected VoidOnDestroy () {2. // leave the room. 3. anychat. leaveRoom (-1); 4. // log out. anychat. logout (); 6. // release the resource, close the SDK, and no longer return to the logon page. 7. anychat. release (); 8 .} after leaving the room, you can enter the room again, but after logging out and releasing resources, the SDK will no longer work. At the end of the Activity life cycle, the occupied resources can be released and the program exits. If you are interested, you can download the test on the official website for free or add QQ for communication.

Related Article

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.