|
5#
楼主 |
发表于 2013-11-26 11:27:00
|
只看该作者
- // 初始化SDK 连接服务器
- private void loginSystem(){
- if (anychat == null){
- anychat = new AnyChatCoreSDK();
- anychat.SetBaseEvent(this); // 设置基本事件回调函数
- ApplyVideoConfig();
- anychat.mSensorHelper.InitSensor(this);
- if (configEntity.useARMv6Lib != 0) // 使用ARMv6指令集
- anychat.SetSDKOptionInt(AnyChatDefine.
- BRAC_SO_CORESDK_USEARMV6LIB, 1);
- anychat.InitSDK(android.os.Build.VERSION.SDK_INT, 0); // 初始化SDK
- }
- anychat.Connect("demo.anychat.cn", 8906);
- }
- // 显示即时视频通话画面
- public void VideoChat(){
- if (!bOtherVideoOpened){
- // System.out.println("camera state =" + anychat.GetCameraState(userid) + " userVideoWidth="+anychat.GetUserVideoWidth(userid));
- if (anychat.GetCameraState(userid) == 2
- && anychat.GetUserVideoWidth(userid) != 0){
- SurfaceHolder holder = remoteSurfaceView.getHolder();
- holder.setFormat(PixelFormat.RGB_565);
- holder.setFixedSize(anychat.GetUserVideoWidth(userid),
- anychat.GetUserVideoHeight(userid));
- Surface s = holder.getSurface(); // 获得视频画面
- anychat.SetVideoPos(userid, s, 0, 0, 0, 0); // 调用API显示视频画面
- bOtherVideoOpened = true;
- }
- }
- if (!bSelfVideoOpened){
- System.out.println("camera state =" + anychat.GetCameraState(-1) + " userVideoWidth="+anychat.GetUserVideoWidth(-1));
- if (anychat.GetCameraState(-1) == 2
- && anychat.GetUserVideoWidth(-1) != 0){
- SurfaceHolder holder = localSurfaceView.getHolder();
- holder.setFormat(PixelFormat.RGB_565);
- holder.setFixedSize(anychat.GetUserVideoWidth(-1),
- anychat.GetUserVideoHeight(-1));
- Surface s = holder.getSurface();
- anychat.SetVideoPos(-1, s, 0, 0, 0, 0);
- bSelfVideoOpened = true;
- }
- }
- }
复制代码- public void OnAnyChatEnterRoomMessage(int dwRoomId, int dwErrorCode){
- if (dwErrorCode == 0) { // 进入房间成功 打开本地音视频
- Toast.makeText(this, "进入房间成功", Toast.LENGTH_SHORT).show();
-
- // 如果是采用Java视频采集,则需要设置Surface的CallBack
- if(AnyChatCoreSDK.GetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_CAPDRIVER) == AnyChatDefine.VIDEOCAP_DRIVER_JAVA) {
- localSurfaceView.getHolder().addCallback(AnyChatCoreSDK.mCameraHelper);
- System.out.println("#####local addCallback");
- }
- if (configEntity.videoOverlay != 0) {
- localSurfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
- }
-
- String[] strVideoCaptures = anychat.EnumVideoCapture();
- if (strVideoCaptures != null && strVideoCaptures.length > 1) {
- // 默认打开前置摄像头
- for(int i=0;i<strVideoCaptures.length;i++)
- {
- System.out.println("#####Camers size="+strVideoCaptures.length);
- String strDevices=strVideoCaptures[i];
- if(strDevices.indexOf("Front")>=0) {
- anychat.SelectVideoCapture(strDevices);
- break;
- }
- }
- }
-
- anychat.UserCameraControl(-1, 1); // 打开本地视频
- anychat.UserSpeakControl(-1, 1); // 打开本地音频
- } else {
- Toast.makeText(this, "进入房间失败,错误代码:" + dwErrorCode, Toast.LENGTH_SHORT).show();
- }
- }
复制代码- /*
- 和视频中第一个用户视频
- */
- public void OnAnyChatOnlineUserMessage(int dwUserNum, int dwRoomId){
- if (dwRoomId == 2){
- int user[] = anychat.GetOnlineUser();
- if (user.length != 0){
- for (int i = 0; i < user.length; i++){
- userlist.add(user[i]+"");
- }
- String temp =userlist.get(0);
- userid = Integer.parseInt(temp);
- anychat.UserCameraControl(userid, 1);// 请求用户视频
- anychat.UserSpeakControl(userid, 1); // 请求用户音频
-
- // 如果是采用Java视频显示,则需要设置Surface的CallBack
- if(AnyChatCoreSDK.GetSDKOptionInt(AnyChatDefine.BRAC_SO_VIDEOSHOW_DRIVERCTRL) == AnyChatDefine.VIDEOSHOW_DRIVER_JAVA) {
- int index = anychat.mVideoHelper.bindVideo(remoteSurfaceView.getHolder());
- anychat.mVideoHelper.SetVideoUser(index, userid);
- }
- }
- else {
- Toast.makeText(VideoChatActivity.this, "当前没有在线用户", Toast.LENGTH_SHORT).show();
- }
- }
- }
复制代码 |
|