AnyChat的視頻會議程序實例詳解
AnyChat(全名叫Anychat SDK),也叫音視頻互動開發(fā)平臺;是一套跨平臺的即時通訊解決方案,基于先進的H.264視頻編碼標準、AAC音頻編碼標準與P2P技術,整合了佰銳科技在音視頻編碼、多媒體通訊領域領先的開發(fā)技術和豐富的產(chǎn)品經(jīng)驗而設計的高質量、寬適應性、分布式、模塊化的網(wǎng)絡音視頻互動平臺。
可以進行雙人或多人的語音實時通話,支持Windows、Web、Android、iOS、Mac、Linux等跨平臺通信。
所提供的SDK支持C++、Delphi、Java、C#、VB、object-c等多種語音開發(fā)。
AnyChat包括音頻視頻錄制,拍照,服務器錄像,文字聊天,文件發(fā)送等多種功能。
界面如下

調(diào)用流程:
1.在所要監(jiān)聽的類中調(diào)用重載WndProc方法,實現(xiàn)windows消息的監(jiān)聽。
/// <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中的獲取方法回調(diào)結果。參數(shù):AnyChatCoreSDK.WM_GV_LOGINSYSTEM)
int ret = AnyChatCoreSDK.Login(PublicMembers.g_Name, "", 0);
}
else
{
PublicMembers.ShowRightTip("登錄失敗。錯誤代碼:" + succed, "");
}
}
else if (m.Msg == AnyChatCoreSDK.WM_GV_LOGINSYSTEM)
{
//客戶端登錄系統(tǒng),wParam(INT)表示自己的用戶ID號
int userid = m.WParam.ToInt32();
if (m.LParam.ToInt32() == 0)
{
m_myUserID = userid;
//進入房間(在WndProc中的獲取方法回調(diào)結果。參數(shù):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)
{
//收到當前房間的在線用戶信息,進入房間后觸發(fā)一次
int usrcnt = m.WParam.ToInt32();
int cnt = 0;//在線用戶數(shù)量
AnyChatCoreSDK.GetOnlineUser(null, ref cnt);//獲取在線用戶數(shù)量
int[] userArr = new int[cnt];//在線用戶ID
AnyChatCoreSDK.GetOnlineUser(userArr, ref cnt);//獲取在線用戶ID數(shù)組
}
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();
//發(fā)生狀態(tài)
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
//設置回調(diào)函數(shù) SystemSetting.Text_OnReceive = new TextReceivedHandler(Received_CallBack);//文本回調(diào)涵數(shù) SystemSetting.TransBuffer_OnReceive = new TransBufferReceivedHandler(Received_TransBuffer);//透明通道傳輸回調(diào) SystemSetting.TransFile_OnReceive = new TransFileReceivedHandler(Received_TransFile);//文件傳輸回調(diào) SystemSetting.TransRecord_OnReceive = new TransRecordHandler(File_CallBack);//拍照錄像回調(diào)函數(shù) //初始化 SystemSetting.Init(this.Handle); //設置內(nèi)核參數(shù) 設置保存路徑 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服務器。執(zhí)行連接操作后會觸發(fā)windows消息回調(diào) AnyChatCoreSDK.WM_GV_CONNECT
//登錄AnyChat (IP從配置文件中獲取) string IP = XmlHelper.GetXmlAttribute(PublicMembers.Config, "http://Configuration//IP", "value").Value; //連接服務器(在WndProc中的獲取方法回調(diào)結果。參數(shù):AnyChatCoreSDK.WM_GV_CONNECT) ret = AnyChatCoreSDK.Connect(IP, 8906);
4.登錄AnyChat服務器。執(zhí)行連接操作后會觸發(fā)windows消息回調(diào) AnyChatCoreSDK.WM_GV_LOGINSYSTEM
//登錄服務器(在WndProc中的獲取方法回調(diào)結果。參數(shù):AnyChatCoreSDK.WM_GV_LOGINSYSTEM) int ret = AnyChatCoreSDK.Login(PublicMembers.g_Name, "", 0);
5.服務器登錄成功后進入指定房間,只有在同一個房間內(nèi)的用戶才可以進行視頻音頻交互。
//進入房間(在WndProc中的獲取方法回調(diào)結果。參數(shù):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.發(fā)送文件,文字,錄制等操作
//發(fā)送文字 int ret = AnyChatCoreSDK.SendTextMessage(-1, true, text, length); //發(fā)送文件 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的視頻會議程序實例詳解的相關內(nèi)容,先給大家介紹這么多,有問題歡迎各位大俠更貼留言,我會及時和大家聯(lián)系的,謝謝大家一直以來對腳本之家網(wǎng)站的支持。

