您的位置:首页 > 其它

AnyChat的视频会议程序实例详解

2016-01-08 09:05 1021 查看

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];//在线用户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);

关于AnyChat的视频会议程序实例详解的相关内容,先给大家介绍这么多,有问题欢迎各位大侠更贴留言,我会及时和大家联系的,谢谢大家一直以来对脚本之家网站的支持。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  anychat 视频 会议