AnyChat是一款跨平臺的音視頻解決方案。php
能夠進行雙人或多人的語音實時通話,支持Windows、Web、Android、iOS、Mac、Linux等跨平臺通訊。windows
所提供的SDK支持C++、Delphi、Java、C#、VB、object-c等多種語音開發。
數組
AnyChat包括音頻視頻錄製,拍照,服務器錄像,文字聊天,文件發送等多種功能。
服務器
界面以下ide
調用流程:函數
1.在所要監聽的類中調用重載WndProc方法,實現windows消息的監聽。this
/// <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];//在線用戶ID AnyChatCoreSDK.GetOnlineUser(userArr, ref cnt);//獲取在線用戶ID數組 } else if (m.Msg == AnyChatCoreSDK.WM_GV_LINKCLOSE) { //客戶端掉線處理 } else if (m.Msg == AnyChatCoreSDK.WM_GV_USERATROOM) { //用戶進入(離開)房間,wParam(INT)表示用戶ID號、 //用戶ID int 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的SDKspa
//設置回調函數 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_CONNECTcode
//登陸AnyChat (IP從配置文件中獲取) string IP = XmlHelper.GetXmlAttribute(PublicMembers.Config, "//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);
最後源碼奉上:http://pan.baidu.com/s/1qXxB1AO
詳細代碼能夠上AnyChat官網獲取,包含SDK,開發文檔,源碼程序等