zoukankan      html  css  js  c++  java
  • 基于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/

    转载于:https://www.cnblogs.com/Mo-MaTure/p/5111769.html

  • 相关阅读:
    Largest Rectangle in Histogram, 求矩形图中最大的长方形面积
    MergeSortedArray,合并两个有序的数组
    Remove Duplicates from Sorted List ,除去链表中相邻的重复元素
    Word Search, 在矩阵中寻找字符串,回溯算法
    SubSets,SubSets2, 求数组所有子集
    Longest Substring Without Repeating Characters,求没有重复字符的最长字串
    Minimum Window Substring, 包含子串的最小窗口,双指针
    Sort Colors,颜色排序
    Search a 2D Matrix,在有序矩阵查找,二分查找的变形; 行有序,列有序查找。
    EditDistance,求两个字符串最小编辑距离,动态规划
  • 原文地址:https://www.cnblogs.com/jijm123/p/14264448.html
Copyright © 2011-2022 走看看