Unity Voice chat--pro-plus Communication Cloud (android/ios)---Android
Source: Internet
Author: User
<span id="Label3"></p><p><p>Note: the recent project needs to do voice chat this piece of function, think of several options, and finally decided to use a third-party services, after all, live 50W below Pro Plus is free!</p></p><p><p>Pro-canada official gave a certain technical documents, but encountered a lot of pits, I introduce the way<br></p></p><p><p>Not much nonsense to say, first introduction to Android access, the next chapter about IOS.</p></p><p><p><br></p></p><p><p>1. Download the Development Kit<br></p></p><p><p>Pro-Plus Development Kit Http://www.gotye.com.cn/download.html</p></p><p><p>Instant Messaging cloud contains rich chat interface, without voice communication cloud, under this development package<br></p></p><p><p><br></p></p><p><p>Android development friends under the Android package, Android Access official documentation is very detailed, and relatively easy, I tried to follow the document does not matter, here is mainly about unity Jieqin plus sdk,unity development must use this plugin, If you want to pick up the Android development package in the SDK environment of the project eclipse, then out of the jar, then the unity out APK package will flash back, only use unity to export the Eclipse project, and then the Android to use, obviously this is too troublesome, rather than directly with the Plugin.<br></p></p><p><p><br></p></p><p><p>2. Import the development package</p></p><p><p>normally, we have all kinds of sdk, such as the various Payment SDK (if not, that is good, imported directly), if any, take care not to import androidmainfest, otherwise it will overwrite the original project configuration file</p></p><p><p><br></p></p><p><p>3. Register your Pro-Plus account and add relevant features</p></p><p><p>To add an app:</p></p><p><p><br></p></p><p><p>Optional open registration is more convenient, after the user login can not password</p></p><p><p>Once created, you will get application information, which will be used in the Appkey Development.</p></p><p><p><br></p></p><p><p>Then add some IM users and chat rooms for testing</p></p><p><p>Add Users:<br></p></p><p><p></p></p><p><p>To add a chat room:<br></p></p><p><p><br></p></p><p><p>4. To the interface, I demonstrate the interface to the voice, the others are similar, drag the file to the scene of a component, appkey with the registration of the success of the key of the lucky couple</p></p><p><p>This example should be run on a real machine, and the simulator will have an Error.<br></p></p><p><p></p></p><pre code_snippet_id="1686814" snippet_file_name="blog_20160517_1_395165" name="code" class="csharp">Using unityengine;using system.collections;using gotye;public class Mainmanager:monobehaviour {public GotyeAPI api; String AppKey = "xxxxxxxxxxxxxxxx"; String PackageName = "com.gotye.api"; Listenerlogin listenerlogin; Listenerchat listenerchat; Listenerroom listenerroom; String Resurt = ""; string text = ""; Static Mainmanager _instance; public static Mainmanager Instance {get {return _instance;} } void Awake () {invokerepeating ("mainloop", 0.0f, 0.050f);//initialize _instance = this; }//use of this for initialization void Start () {//initialize API = Gotyeapi.getinstance (); Api. Init (appKey, packagename); Add Event Callback Listenerlogin = new Listenerlogin (); Listenerchat = new Listenerchat (); Listenerroom = new Listenerroom (); Api. AddListener (listenerlogin); Api. AddListener (listenerchat); Api. AddListener (listenerroom); } void Ongui () {GUI. Label (new Rect (0, n, a), text); Gui. Label (new Rect (n, n, a, a), resurt); If (GUI. Button (new Rect (0, 0, max, +), "sq123 Login")) {text = "sq123 login"; Api. Login ("sq123", null); } If (GUI. Button (new Rect (0, sq222, max), "log In")) {text = "sq222 login"; Api. Login ("sq222", null); } If (GUI. Button (new Rect (0, 200, 200, 100), "enter chat room")) {//298926 text = "enter Chat room"; Gotyeroom = new Gotyeroom (298926); Api. Enterroom (guest); } If (GUI. Button (new Rect (0, 300, 200, 100), "start Talking")) {text = "start speaking"; Gotyeroom = new Gotyeroom (298926); Api. SendMessage (gotyemessage.createtextmessage ("111")); Api. Starttalk (room,0,false,20000); } If (GUI. Button (new Rect (0, 400, 200, 100), "stop Talking")) {text = "stop talking"; Api. Stoptalk (); } If (GUI. Button (new Rect (0, 500, 200, 100), "exit chat Room")) {text = "exit Chat room"; Gotyeroom = new Gotyeroom (298926); Api. Leaveroom (guest); } If (GUI. Button (new Rect (0, 600, 200, 100), "log Out")) {text = "log out"; Api. Logout (); }} void Mainloop ()//initialize {gotyeapi.getinstance (). Mainloop (); }//display GUI information public void showanimate (string log) {text = log; public void Showresurt (string log) {resurt = log; }}</pre><br><p><p></p></p><p><p>The event listener callback inherits the interface provided by the development package and implements all functions in the interface as public</p></p><p><p>Listenerchat: Chat Callback</p></p><p><p></p></p><pre code_snippet_id="1686814" snippet_file_name="blog_20160517_2_886316" name="code" class="csharp">Using unityengine;using system.collections;using gotye;using system.text;using system.collections.generic;public Class listenerchat:chatlistener{/** * Callback after sending message * @param code status code See {@link gotyestatuscode} * The message object that is sent by the @param messages */public void onsendmessage (gotyestatuscode code, gotyemessage message) {M AinManager.Instance.ShowResurt ("send message: code =" + code.) ToString ()); /** * Receive information * @param code status code See {@link gotyestatuscode} * @param message */public void Onreceivem Essage (gotyemessage Message) {if (message. Type = = Gotyemessagetype.text) {MainManager.Instance.ShowResurt ("receive text message"); } else if (message. Type = = Gotyemessagetype.audio) {MainManager.Instance.ShowResurt ("receive Voice message"); MainManager.Instance.api.DownloadMediaInMessage (message); } else {MainManager.Instance.ShowResurt ("receive additional information"); } } /** * Download Message * @param code status code See {@link gotyestatuscode} * Message object downloaded by @param message */public void Ondownloadmedi Ainmessage (gotyestatuscode code, gotyemessage message) {MainManager.Instance.api.PlayMessage (message); }/** * Report Callback * @param code status code See {@link gotyestatuscode} * @param message reported messages */public void OnR Eport (gotyestatuscode code, gotyemessage message) {}/** * Start recording voice message callback * @param code status code see {@link Gotye StatusCode} * @param isrealtime whether real-time voice * @param targetType Send Object type * @param target send object */public void Onstarttalk (gotyestatuscode code, gotyechattarget target, bool Isrealtime) {MainManager.Instance.ShowResurt ("start Recording "); /** * Stop Recording voice message callback * @param code status code See {@link gotyestatuscode} * @param message * @param isvoicereal */public void Onstoptalk (gotyestatuscode code, bool realtime, gotyemessage message/*, bool *cancelsending*/) { Mainmanager.iNstance. Showresurt ("recording completed"); Gotyeroom = new Gotyeroom (298926); MainManager.Instance.api.SendMessage (message); }/** * Decode Voice message * @param code status code See {@link gotyestatuscode} * @param message object decoded */public void Ondecodemessage (gotyestatuscode code, gotyemessage message) {}/** * Get history message Callback * @deprecated * @param code Status code See {@link gotyestatuscode} * @param list history messages */public void Ongetmessagelist (gotyesta Tuscode code, list<gotyemessage> list/*, bool downloadmediaifneed*/) {} public void Onrequestcs (gotyestat Uscode code, gotyeuser user) {}/** * Set Group Message callback * @deprecated * @param code status code see {@link G otyestatuscode} * @param group Current Group * @param message configuration parameters for Msgconfig group */public void Onsetgroupmsgconfi G (gotyestatuscode code, gotyegroup group, gotyegroupmsgconfig msgconfig) {}/** * Get group Message Settings callback * @d eprecated * @param code Status code See {@link gotyestatuscode} * @param group current group */public void Ongetgroupmsgconfig (gotye StatusCode code, gotyegroup group, gotyegroupmsgconfig msgconfig) {}/** * Get offline message callback * @deprecated * @param code Status code See {@link gotyestatuscode} * @param msglist History Message list * @param downloadmediaifneed Need to download multimedia */public void ongetofflinemessagelist (gotyestatuscode code, list<gotyemessage> msglist/*, bool D Ownloadmediaifneed*/) {}/** * Get history Message Callback * @deprecated * @param code status code see {@link Gotyesta tuscode} * @param list history messages */public void Ongethistorymessagelist (gotyestatuscode code, List<gotyemessa ge> msglist/*, BOOL Downloadmediaifneed*/) {}/** * * @deprecated * @param code status code see {@link gotyestatuscode} */public void Onstartapns (gotyestatuscode code) {}/** * * @depr ecated * @param cOde status code See {@link gotyestatuscode} */public void Onstopapns (gotyestatuscode code) {}/** * Update unread messages Callback * @deprecated * @param code status code see {@link gotyestatuscode} */public void Onupdateunreadmessagecoun T (gotyestatuscode code) {} public void ongetlastmessage (gotyechattarget target, gotyemessage Message) { } public void Ongetsessionlist (list<gotyechattarget> List) {} public void Ongetunreadmessagecount (goty Echattarget target, int count) {} public void Ongettotalunreadmessagecount (int. count) {} public void Ongettotalunreadmessagecountoftypes (list<gotyechattargettype> types, int Count) {}}</pre><br>Listenerlogin: Login Callback<p><p></p></p><p><p></p></p><pre code_snippet_id="1686814" snippet_file_name="blog_20160517_3_7124324" name="code" class="csharp"><pre code_snippet_id="1686814" snippet_file_name="blog_20160517_3_7124324" name="code" class="csharp">Using unityengine;using system.collections;using gotye;public class listenerlogin:loginlistener{public void Onlogin (gotyestatuscode code, gotyeuser user) { MainManager.Instance.ShowResurt ("users login:" + user.) Name + "code =" + code. ToString ()); } public void Onlogout (gotyestatuscode code) { MainManager.Instance.ShowResurt ("user logout: code =" + code.) ToString ()); } public void onreconnecting (gotyestatuscode code, gotyeuser currentUser) { MainManager.Instance.ShowResurt ( "user reconnect: Code =" + Code. ToString () + "id =" + currentuser.name);} }</pre></pre><br>listenerroom: Chat Room Callback<p><p></p></p><p><p></p></p><pre code_snippet_id="1686814" snippet_file_name="blog_20160517_4_1377467" name="code" class="csharp">Using unityengine;using system.collections;using system.collections.generic;using gotye;public class ListenerRoom: roomlistener{/** * Enter Chat room callback * @param code status code See {@link gotyestatuscode} * @param room Current Chat object */pu blic void Onenterroom (gotyestatuscode code, gotyeroom room) {MainManager.Instance.ShowResurt ("enter Rooms code =" + C Ode. ToString () + "roomid =" + room.id); /** * Leave the chat room * @param code status code See {@link gotyestatuscode} * @param room Current Chat object */public void Onle Averoom (gotyestatuscode code, gotyeroom rooms) {MainManager.Instance.ShowResurt ("leave Room code =" + code.) ToString () + "roomid =" + room.id); /** * Go back to the chat room list * @param code status code See {@link gotyestatuscode} * @param gotyeroom chat room list */public void ongetroomlist (gotyestatuscode code, int pageIndex, list<gotyeroom> curpageroomlist, list<gotyeroom> Allroomlist) {}/** * Get a list of Chat room members * @param code status code see {@link Gotyestatuscode} * @param room Current Chat * @param totalmembers result collection per page * @param currentpagemembers Current Page collection * @param pa Geindex current page */public void ongetroommemberlist (gotyestatuscode code, gotyeroom, int pageIndex, LIST&L T gotyeuser> currentpagemembers, list<gotyeuser> totalmembers) {} public void Ongetlocalroomlist (List< gotyeroom> curpageroomlist) {} public void Ongetroomdetail (gotyestatuscode code, gotyeroom guest) {} public void Ongetroomstatus (gotyeroom guest, bool in) {} public void Ongetroomrealtimestatus (gotyeroom, bo OL support) {}}</pre><br>After these files are imported, use unity to export the Eclipse project, Delete the three unity files under the exported project src, and then delete the original project Master jar Package.<p><p></p></p><p><p>Then merge the Project SDK environment and initialize the Pro-Plus API in OnCreate () to start the activity, adding this line:</p></p><p><p></p></p><pre code_snippet_id="1686814" snippet_file_name="blog_20160517_5_4027425" name="code" class="csharp"><pre code_snippet_id="1686814" snippet_file_name="blog_20160517_5_4027425" name="code" class="csharp">Gotyeapi.getinstance (). init (getapplicationcontext (), "6e6c4968-b491-4fbf-8ff1-68b06ee134ee", GotyeAPI.SCENE_ unity3d);</pre></pre>run, there will be reported some file errors, such as resource.ap_, are deleted, until you can run on the phone, and then use two mobile phone conversations, voice can receive each other, most of the content is Finished.<p><p></p></p><p><p>To do this step, the package has been able to out, but for convenience, or with unity out of the package is better, otherwise the Eclipse project will lead to the collapse of people!</p></p><p><p><br></p></p><p><p>5. Export the jar package and use unity out apk</p></p><p><p>Use this project to export a master jar package, overwrite the original, and then use the unity out APK</p></p><p><p><br></p></p><p><p>Once again, this big pit:</p></p><p><p>Do not add a jar package to Unity's SDK environment with the pro-android development package, and then use unity to go out of the Package. The report can't find the contents of the error, this is a big hole!</p></p><p><p>New project in Eclipse Import development environment test run no problem, always feel is a package is ok, but import into unity on the crash, who knows what this reason is also hope to inform.</p></p><p><p><br></p></p><p><p><br></p></p><p><p>Unity Voice chat--pro-plus Communication Cloud (android/ios)---Android</p></p></span>
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