基於AnyChat的視頻會議程序


  AnyChat是一款跨平台的音視頻解決方案。

  可以進行雙人或多人的語音實時通話,支持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];//在線用戶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的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, "//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,開發文檔,源碼程序等

  官網地址:http://www.anychat.cn/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM