AnyChat(全名叫Anychat SDK),也叫音視頻互動開發平臺;是一套跨平臺的即時通訊解決方案,基于先進的H.264視頻編碼標準、AAC音頻編碼標準與P2P技術,整合了佰銳科技在音視頻編碼、多媒體通訊領域領先的開發技術和豐富的產品經驗而設計的高質量、寬適應性、分布式、模塊化的網絡音視頻互動平臺。
可以進行雙人或多人的語音實時通話,支持Windows、Web、Android、iOS、Mac、Linux等跨平臺通信。
所提供的SDK支持C++、Delphi、Java、C#、VB、object-c等多種語音開發。
AnyChat包括音頻視頻錄制,拍照,服務器錄像,文字聊天,文件發送等多種功能。
界面如下
調用流程:
1.在所要監聽的類中調用重載WndProc方法,實現windows消息的監聽。
/// <summary>/// 重載/// </summary>/// <param name="m"></param>protected override void WndProc(ref Message m){if (m.Msg == AnyChatCoreSDK.WM_GV_CONNECT){//客戶端連接服務器,表示是否連接成功int succed = m.WParam.ToInt32();//連接服務器成功if (succed == 1){//登錄服務器(在WndProc中的獲取方法回調結果。參數:AnyChatCoreSDK.WM_GV_LOGINSYSTEM)int ret = AnyChatCoreSDK.Login(PublicMembers.g_Name, "", 0);}else{PublicMembers.ShowRightTip("登錄失敗。錯誤代碼:" + succed, "");}}else if (m.Msg == AnyChatCoreSDK.WM_GV_LOGINSYSTEM){//客戶端登錄系統,wParam(INT)表示自己的用戶ID號int userid = m.WParam.ToInt32();if (m.LParam.ToInt32() == 0){m_myUserID = userid;//進入房間(在WndProc中的獲取方法回調結果。參數:AnyChatCoreSDK.WM_GV_ENTERROOM)int ret = AnyChatCoreSDK.EnterRoom(m_RoomID, "", 0);}else{MessageBox.Show("登錄服務器失敗,代碼出錯為:" + m.LParam.ToInt32(), "警告");}}else if (m.Msg == AnyChatCoreSDK.WM_GV_ENTERROOM){//客戶端進入房間if (m.LParam.ToInt32() == 0){//綁定本機視頻窗口 -1代表自己int ret = AnyChatCoreSDK.SetVideoPos(-1, picLocalVideo.Handle, 0, 0, picLocalVideo.Width, picLocalVideo.Height);//開啟本地視頻 -1代表自己ret = AnyChatCoreSDK.UserCameraControl(-1, true);//開啟本地聲音 -1代表自己ret = AnyChatCoreSDK.UserSpeakControl(-1, true);}else{MessageBox.Show("申請進入房間失敗,出錯代碼為:" + m.LParam.ToInt32(), "警告");}}else if (m.Msg == AnyChatCoreSDK.WM_GV_ONLINEUSER){//收到當前房間的在線用戶信息,進入房間后觸發一次int usrcnt = m.WParam.ToInt32();int cnt = 0;//在線用戶數量AnyChatCoreSDK.GetOnlineUser(null, ref cnt);//獲取在線用戶數量int[] userArr = new int[cnt];//在線用戶IDAnyChatCoreSDK.GetOnlineUser(userArr, ref cnt);//獲取在線用戶ID數組}else if (m.Msg == AnyChatCoreSDK.WM_GV_LINKCLOSE){//客戶端掉線處理}else if (m.Msg == AnyChatCoreSDK.WM_GV_USERATROOM){//用戶進入(離開)房間,wParam(INT)表示用戶ID號、//用戶IDint userID = m.WParam.ToInt32();//發生狀態int boEntered = m.LParam.ToInt32();if (boEntered == 1){//進入房間m_others.Add(userID);StartVideo(userID);}else{//退出房間m_others.Remove(userID);EndVideo(userID);}}base.WndProc(ref m);}
2.初始化AnyChat的SDK
//設置回調函數SystemSetting.Text_OnReceive = new TextReceivedHandler(Received_CallBack);//文本回調涵數SystemSetting.TransBuffer_OnReceive = new TransBufferReceivedHandler(Received_TransBuffer);//透明通道傳輸回調SystemSetting.TransFile_OnReceive = new TransFileReceivedHandler(Received_TransFile);//文件傳輸回調SystemSetting.TransRecord_OnReceive = new TransRecordHandler(File_CallBack);//拍照錄像回調函數//初始化SystemSetting.Init(this.Handle);//設置內核參數 設置保存路徑int ret = 0;ret = AnyChatCoreSDK.SetSDKOption(AnyChatCoreSDK.BRAC_SO_RECORD_TMPDIR, Application.StartupPath, Application.StartupPath.Length);ret = AnyChatCoreSDK.SetSDKOption(AnyChatCoreSDK.BRAC_SO_SNAPSHOT_TMPDIR, Application.StartupPath, Application.StartupPath.Length);
3.連接AnyChat服務器。使用AnyChat功能必須先連接并登錄AnyChat服務器。執行連接操作后會觸發windows消息回調 AnyChatCoreSDK.WM_GV_CONNECT
//登錄AnyChat (IP從配置文件中獲取)string IP = XmlHelper.GetXmlAttribute(PublicMembers.Config, "http://Configuration//IP", "value").Value;//連接服務器(在WndProc中的獲取方法回調結果。參數:AnyChatCoreSDK.WM_GV_CONNECT)ret = AnyChatCoreSDK.Connect(IP, 8906);
4.登錄AnyChat服務器。執行連接操作后會觸發windows消息回調 AnyChatCoreSDK.WM_GV_LOGINSYSTEM
//登錄服務器(在WndProc中的獲取方法回調結果。參數:AnyChatCoreSDK.WM_GV_LOGINSYSTEM)int ret = AnyChatCoreSDK.Login(PublicMembers.g_Name, "", 0);
5.服務器登錄成功后進入指定房間,只有在同一個房間內的用戶才可以進行視頻音頻交互。
//進入房間(在WndProc中的獲取方法回調結果。參數:AnyChatCoreSDK.WM_GV_ENTERROOM)int ret = AnyChatCoreSDK.EnterRoom(m_RoomID, "", 0);
6.打開,關閉音頻視頻
//綁定本機視頻窗口 -1代表自己,通過指定userId來綁定視頻窗口int ret = AnyChatCoreSDK.SetVideoPos(-1, picLocalVideo.Handle, 0, 0, picLocalVideo.Width, picLocalVideo.Height);//開啟本地視頻 -1代表自己ret = AnyChatCoreSDK.UserCameraControl(-1, true);//開啟本地聲音 -1代表自己ret = AnyChatCoreSDK.UserSpeakControl(-1, true);
7.發送文件,文字,錄制等操作
//發送文字int ret = AnyChatCoreSDK.SendTextMessage(-1, true, text, length);//發送文件 filepath:文件路徑int taskId = 0;int flag = AnyChatCoreSDK.TransFile(userId, filepath, 1, 0, 0, ref taskId);//開啟聲音int ret = AnyChatCoreSDK.UserSpeakControl(userId, true);//關閉聲音int ret = AnyChatCoreSDK.UserSpeakControl(userId, false);//開啟視頻int ret = AnyChatCoreSDK.UserCameraControl(userId, true);//關閉視頻int ret = AnyChatCoreSDK.UserCameraControl(userId, false);//開始錄像ulong flag = 0;//0為錄制視頻 1為錄制音頻int ret = AnyChatCoreSDK.StreamRecordCtrl(userId, true, flag, 0);//停止錄像ulong flag = 0;//0為錄制視頻 1為錄制音頻int ret = AnyChatCoreSDK.StreamRecordCtrl(userId, false, flag, 0);//拍照AnyChatCoreSDK.SnapShot(userId, 1, 1);
關于AnyChat的視頻會議程序實例詳解的相關內容,先給大家介紹這么多,有問題歡迎各位大俠更貼留言,我會及時和大家聯系的,謝謝大家一直以來對武林網網站的支持。
新聞熱點
疑難解答