AnyChatSDK 实现视频通话

公司的项目需要添加视频通话功能,公司选择使用AnyChatSDK来实现;

①下载:

地址:http://www.anychat.cn/download.html;

这里官方提供了完成的Demo和开发文档可以下载

②我们目前采用的是消息队列,我重点介绍这一部分

package com.bairuitech.main;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.inputmethod.InputMethodManager;

import com.bairuitech.anychat.AnyChatBaseEvent;
import com.bairuitech.anychat.AnyChatCoreSDK;
import com.bairuitech.anychat.AnyChatDefine;
import com.bairuitech.anychat.AnyChatObjectDefine;
import com.bairuitech.anychat.AnyChatObjectEvent;
import com.bairuitech.anychat.AnyChatVideoCallEvent;
import com.bairuitech.common.ConfigEntity;
import com.bairuitech.common.ConfigService;
import com.bairuitech.common.DialogFactory;
import com.bairuitech.common.ScreenInfo;

public class AnyChat_Login implements AnyChatBaseEvent, AnyChatObjectEvent,
        AnyChatVideoCallEvent {
    // private static final String mStrIP = "demo.anychat.cn";
    private static final String mStrIP = "**.*.*.***";  //服务器地址
    private static final int mSPort = ****;             //端口号
    private static final String TAG = "AnyChat_Login";
    private String mStrName = "Tom";
    private String passWord;
    private List<Integer> mobject = new ArrayList<Integer>(); // 装载营业厅ID
    private int[] queueIds;

    private int USER_TYPE_ID; // 0代表是进入客户界面,2代表是接入座席界面

    public AnyChatCoreSDK anyChatSDK;
    private AnyChat_LoginCallBack loginCallback;
    private AnyChat_GetFunRoomCallBack roomCallBack;
    private AnyChat_UpdateQueueInfoCallBack updateCallBack;
    private AnyChat_VideoResultCallBack videoCallBack;
    private Activity context;
    private QueueInfoEntity entity;
    private long time;

    /**
     * 用户当前状态
     *
     * @author Administrator
     *
     */
    public enum LoginStatus {
        Success, Waiting, Failure, Finish, NoNet, UnKnownErr, Reconnection
    }

    /**
     *
     * @param context
     *            上下文环境
     * @param termId
     *            终端号 (用户名)
     * @param applyId
     *            业务ID(Password)
     */
    public AnyChat_Login(Activity context, String termId, String applyId) {
        this.context = context;
        this.mStrName = termId;
        this.passWord = applyId;
        entity = QueueInfoEntity.getQueueInfoEntity();
        setDisPlayMetrics();
        ApplyVideoConfig();
        InitSDK();
    }

    public void setAnyChat_LoginCallBack(AnyChat_LoginCallBack callback) {
        this.loginCallback = callback;
    }

    public void setAnyChat_GetFunRoom(AnyChat_GetFunRoomCallBack callback) {
        this.roomCallBack = callback;
    }

    public void setUpdateCallBack(AnyChat_UpdateQueueInfoCallBack updateCallBack) {
        this.updateCallBack = updateCallBack;
    }

    public void setVideoCallBack(AnyChat_VideoResultCallBack videoCallBack) {
        this.videoCallBack = videoCallBack;
    }

    // 初始化SDK
    private void InitSDK() {
        if (anyChatSDK == null) {
            anyChatSDK = AnyChatCoreSDK.getInstance(context);
        }
        anyChatSDK.SetBaseEvent(this);// 基本事件
        anyChatSDK.SetObjectEvent(this);// 营业厅排队事件
        anyChatSDK.SetVideoCallEvent(this);
        anyChatSDK.InitSDK(android.os.Build.VERSION.SDK_INT, 0);// 初始化sdk
        AnyChatCoreSDK.SetSDKOptionInt(
                AnyChatDefine.BRAC_SO_LOCALVIDEO_AUTOROTATION, 1);
    }

    public void loginAnyChat() {
        loginCallback.getLoginStatus(LoginStatus.Waiting, -1);
        anyChatSDK.Connect(mStrIP, mSPort);
        // 注册广播
        registerBoradcastReceiver();
    }

    // 对键盘显示进行控制
    private void hideKeyboard() {
        InputMethodManager imm = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm.isActive()) {
            imm.hideSoftInputFromWindow(context.getCurrentFocus()
                    .getApplicationWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }

    /**
     * 屏幕大小
     */
    private void setDisPlayMetrics() {
        DisplayMetrics dMetrics = new DisplayMetrics();
        context.getWindowManager().getDefaultDisplay().getMetrics(dMetrics);
        ScreenInfo.WIDTH = dMetrics.widthPixels;
        ScreenInfo.HEIGHT = dMetrics.heightPixels;
    }

    public void onDestroy() {
        anyChatSDK.LeaveRoom(-1);
        anyChatSDK.Logout();
        anyChatSDK.Release();
        context.unregisterReceiver(mBroadcastReceiver);
    }

    public void onRestart() {
        anyChatSDK.SetBaseEvent(this);
        anyChatSDK.SetObjectEvent(this);
    }

    @Override
    public void OnAnyChatConnectMessage(boolean bSuccess) {
        if (!bSuccess) {
            Log.e(TAG, "连接服务器失败,自动重连,请稍后...");
            loginCallback.getLoginStatus(LoginStatus.Reconnection, -1);
        }
        anyChatSDK.Login(mStrName, passWord);
    }

    @Override
    public void OnAnyChatLoginMessage(int dwUserId, int dwErrorCode) {
        // 连接成功

        if (dwErrorCode == 0) {
            // hideKeyboard();
            // 保存用户id和用户角色信息
            entity.selfUserName = mStrName;
            entity.mUserID = dwUserId;
            entity.userType = USER_TYPE_ID;
            Log.e(TAG, "Connect to the server success");
            // 初始化业务对象属性身份
            InitClientObjectInfo(dwUserId);
            loginCallback.getLoginStatus(LoginStatus.Success, dwUserId);

        } else {
            Log.e(TAG, "登录失败,errorCode:" + dwErrorCode);
            loginCallback.getLoginStatus(LoginStatus.Failure, -1);
        }
    }

    // 初始化服务对象事件;触发回调OnAnyChatObjectEvent函数
    private void InitClientObjectInfo(int dwUserId) {
        // 业务对象身份初始化;0代表普通客户,2是代表座席 (USER_TYPE_ID)
        AnyChatCoreSDK.SetSDKOptionInt(AnyChatDefine.BRAC_SO_OBJECT_INITFLAGS,
                USER_TYPE_ID);
        // 业务对象优先级设定;
        int dwPriority = 10;
        AnyChatCoreSDK.ObjectSetIntValue(
                AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_CLIENTUSER, dwUserId,
                AnyChatObjectDefine.ANYCHAT_OBJECT_INFO_PRIORITY, dwPriority);
        // 业务对象属性设定,必须是-1;
        int dwAttribute = -1;
        AnyChatCoreSDK.ObjectSetIntValue(
                AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_CLIENTUSER, dwUserId,
                AnyChatObjectDefine.ANYCHAT_OBJECT_INFO_ATTRIBUTE, dwAttribute);
        // 向服务器发送数据同步请求指令
        AnyChatCoreSDK.ObjectControl(
                AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_AREA,
                AnyChatObjectDefine.ANYCHAT_INVALID_OBJECT_ID,
                AnyChatObjectDefine.ANYCHAT_OBJECT_CTRL_SYNCDATA, dwUserId, 0,
                0, 0, "");
    }

    @Override
    public void OnAnyChatEnterRoomMessage(int dwRoomId, int dwErrorCode) {

    }

    @Override
    public void OnAnyChatOnlineUserMessage(int dwUserNum, int dwRoomId) {

    }

    @Override
    public void OnAnyChatUserAtRoomMessage(int dwUserId, boolean bEnter) {

    }

    // 网络端口
    @Override
    public void OnAnyChatLinkCloseMessage(int dwErrorCode) {
        anyChatSDK.LeaveRoom(-1);
        anyChatSDK.Logout();
        Log.e(TAG, "连接关闭,errorCode:" + dwErrorCode);
        loginCallback.getLoginStatus(LoginStatus.UnKnownErr, -1);

    }

    // 广播
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals("NetworkDiscon")) {
                anyChatSDK.LeaveRoom(-1);
                anyChatSDK.Logout();
                loginCallback.getLoginStatus(LoginStatus.NoNet, -1);
            }
        }
    };

    private void registerBoradcastReceiver() {
        IntentFilter myIntentFilter = new IntentFilter();
        myIntentFilter.addAction("NetworkDiscon");
        // 注册广播
        context.registerReceiver(mBroadcastReceiver, myIntentFilter);
    }

    @Override
    public void OnAnyChatObjectEvent(int dwObjectType, int dwObjectId,
            int dwEventType, int dwParam1, int dwParam2, int dwParam3,
            int dwParam4, String strParam) {
        Log.e("OnAnyChatObjectEvent", "----------------");
        switch (dwEventType) {

        // 营业厅数据同步,回调一次返回一个营业厅对象id(有多少营业厅回调多少次)
        case AnyChatObjectDefine.ANYCHAT_OBJECT_EVENT_UPDATE:
            // 装入集合
            mobject.add(dwObjectId);

            break;

        // 进入营业厅结果回调
        case AnyChatObjectDefine.ANYCHAT_AREA_EVENT_ENTERRESULT:

            AnyChatEnterAreaResult(dwObjectType, dwObjectId, dwParam1);
            break;

        case AnyChatObjectDefine.ANYCHAT_AREA_EVENT_LEAVERESULT:
            Log.e(TAG, "退出营业厅");
            context.finish();
            break;
        // 数据同步完成回调
        case AnyChatObjectDefine.ANYCHAT_OBJECT_EVENT_SYNCDATAFINISH:

            DataFinshed(dwObjectType);
            break;
        case AnyChatObjectDefine.ANYCHAT_QUEUE_EVENT_ENTERRESULT:
            break;
        case AnyChatObjectDefine.ANYCHAT_QUEUE_EVENT_STATUSCHANGE:
            updateCallBack.onUpdateQueueInfo(dwObjectId);
            break;
        }
    }

    // 进入营业厅的回调,跳转到业务列表
    private void AnyChatEnterAreaResult(int dwObjectType, int dwObjectId,
            int dwParam1) {
        // dwParam1 进入营业厅返回结果,0表示进入营业厅成功
        Log.e(TAG, "TAG:" + "dwObjectType:" + dwObjectType + ";dwObjectId:"
                + dwObjectId + ";dwParam1:" + dwParam1);
        // 客户角色
        if (entity.userType == 0) {
            startDeal();
            // 座席角色
        }
    }

    private void DataFinshed(int dwObjectType) {
        Log.e("TAG", "dwObjectType:" + dwObjectType);
        if (dwObjectType == AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_AREA) {
            // 适配器的数据获取
            List<String> list = new ArrayList<String>();
            for (int index = 0; index < mobject.size(); index++) {
                String name = AnyChatCoreSDK.ObjectGetStringValue(
                        AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_AREA,
                        mobject.get(index),
                        AnyChatObjectDefine.ANYCHAT_OBJECT_INFO_NAME);
                list.add(name);
                Log.e("TAG", "TAG:" + index + "; name:" + name);
            }
            roomCallBack.getAnyChat_GetFunRoom(mobject);
        }
    }

    /**
     * 根据配置文件配置视频参数
     */
    private void ApplyVideoConfig() {
        ConfigEntity configEntity = ConfigService.LoadConfig(context);
        if (configEntity.configMode == 1) // 自定义视频参数配置
        {
            // 设置本地视频编码的码率(如果码率为0,则表示使用质量优先模式)
            AnyChatCoreSDK.SetSDKOptionInt(
                    AnyChatDefine.BRAC_SO_LOCALVIDEO_BITRATECTRL,
                    configEntity.videoBitrate);
            if (configEntity.videoBitrate == 0) {
                // 设置本地视频编码的质量
                AnyChatCoreSDK.SetSDKOptionInt(
                        AnyChatDefine.BRAC_SO_LOCALVIDEO_QUALITYCTRL,
                        configEntity.videoQuality);
            }
            // 设置本地视频编码的帧率
            AnyChatCoreSDK.SetSDKOptionInt(
                    AnyChatDefine.BRAC_SO_LOCALVIDEO_FPSCTRL,
                    configEntity.videoFps);
            // 设置本地视频编码的关键帧间隔
            AnyChatCoreSDK.SetSDKOptionInt(
                    AnyChatDefine.BRAC_SO_LOCALVIDEO_GOPCTRL,
                    configEntity.videoFps * 4);
            // 设置本地视频采集分辨率
            AnyChatCoreSDK.SetSDKOptionInt(
                    AnyChatDefine.BRAC_SO_LOCALVIDEO_WIDTHCTRL,
                    configEntity.resolution_width);
            AnyChatCoreSDK.SetSDKOptionInt(
                    AnyChatDefine.BRAC_SO_LOCALVIDEO_HEIGHTCTRL,
                    configEntity.resolution_height);
            // 设置视频编码预设参数(值越大,编码质量越高,占用CPU资源也会越高)
            AnyChatCoreSDK.SetSDKOptionInt(
                    AnyChatDefine.BRAC_SO_LOCALVIDEO_PRESETCTRL,
                    configEntity.videoPreset);
        }
        // 让视频参数生效
        AnyChatCoreSDK.SetSDKOptionInt(
                AnyChatDefine.BRAC_SO_LOCALVIDEO_APPLYPARAM,
                configEntity.configMode);
        // P2P设置
        AnyChatCoreSDK.SetSDKOptionInt(
                AnyChatDefine.BRAC_SO_NETWORK_P2PPOLITIC,
                configEntity.enableP2P);
        // 本地视频Overlay模式设置
        AnyChatCoreSDK.SetSDKOptionInt(
                AnyChatDefine.BRAC_SO_LOCALVIDEO_OVERLAY,
                configEntity.videoOverlay);
        // 回音消除设置
        AnyChatCoreSDK.SetSDKOptionInt(AnyChatDefine.BRAC_SO_AUDIO_ECHOCTRL,
                configEntity.enableAEC);
        // 平台硬件编码设置
        AnyChatCoreSDK.SetSDKOptionInt(
                AnyChatDefine.BRAC_SO_CORESDK_USEHWCODEC,
                configEntity.useHWCodec);
        // 视频旋转模式设置
        AnyChatCoreSDK.SetSDKOptionInt(
                AnyChatDefine.BRAC_SO_LOCALVIDEO_ROTATECTRL,
                configEntity.videorotatemode);
        // 本地视频采集偏色修正设置
        AnyChatCoreSDK.SetSDKOptionInt(
                AnyChatDefine.BRAC_SO_LOCALVIDEO_FIXCOLORDEVIA,
                configEntity.fixcolordeviation);
        // 视频GPU渲染设置
        AnyChatCoreSDK.SetSDKOptionInt(
                AnyChatDefine.BRAC_SO_VIDEOSHOW_GPUDIRECTRENDER,
                configEntity.videoShowGPURender);
        // 本地视频自动旋转设置
        AnyChatCoreSDK.SetSDKOptionInt(
                AnyChatDefine.BRAC_SO_LOCALVIDEO_AUTOROTATION,
                configEntity.videoAutoRotation);
    }

    @Override
    public void OnAnyChatVideoCallEvent(int dwEventType, int dwUserId,
            int dwErrorCode, int dwFlags, int dwParam, String userStr) {
        Log.e("OnAnyChatVideoCallEvent", "dwEventType:" + dwEventType
                + ";dwErrorCode:" + dwErrorCode);
        switch (dwEventType) {

        case AnyChatDefine.BRAC_VIDEOCALL_EVENT_REQUEST:
            // 呼叫请求事件
            BussinessCenter.getBussinessCenter().onVideoCallRequest(dwUserId,
                    dwFlags, dwParam, userStr);
            entity.targetUserName = anyChatSDK.GetUserName(dwUserId);
            Dialog dialog = DialogFactory.getDialog(DialogFactory.DIALOGID_REQUEST,
                    dwUserId, context,entity);
            dialog.show();
            break;

        case AnyChatDefine.BRAC_VIDEOCALL_EVENT_REPLY:
            // 呼叫成功的时候的所做出的反应;
            Log.e("queueactivity", "呼叫成功等待对方反应的回调");
            BussinessCenter.getBussinessCenter().onVideoCallReply(dwUserId,
                    dwErrorCode, dwFlags, dwParam, userStr, videoCallBack);
            if (dwErrorCode == AnyChatDefine.BRAC_ERRORCODE_SUCCESS) {

            } else {
            }
            break;

        case AnyChatDefine.BRAC_VIDEOCALL_EVENT_START:
            Log.e("queueactivity", "会话开始回调");
            entity.TargetUserId = dwUserId;
            entity.RoomId = dwParam;
            BussinessCenter.getBussinessCenter().stopSessionMusic();
            videoCallBack.onAnyChat_VieoResult(dwUserId);
            break;
        }
    }

    /**
     * 用户当前状态
     *
     * @author Administrator
     *
     */
    public interface AnyChat_LoginCallBack {
        public void getLoginStatus(LoginStatus status, int dwUserId);
    }

    /**
     * 返回营业厅ID
     *
     * @author Administrator
     *
     */
    public interface AnyChat_GetFunRoomCallBack {
        public void getAnyChat_GetFunRoom(List<Integer> list);
    }

    /**
     * 立即办理
     */
    public void startDeal() {
        queueIds = AnyChatCoreSDK
                .ObjectGetIdList(AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_QUEUE);
        for (int i = 0; i < queueIds.length; i++) {
            String name = AnyChatCoreSDK.ObjectGetStringValue(
                    AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_QUEUE, queueIds[i],
                    AnyChatObjectDefine.ANYCHAT_OBJECT_INFO_NAME);
            int number = AnyChatCoreSDK.ObjectGetIntValue(
                    AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_QUEUE, queueIds[i],
                    AnyChatObjectDefine.ANYCHAT_QUEUE_INFO_LENGTH);
            Log.e("TAG", "业务字符名称:" + name + ";业务排队人数:" + number);
        }
        if (queueIds != null && queueIds.length != 0) {
            entity.CurrentQueueId = (queueIds[0]);
            // 进入队列的控制指令
            AnyChatCoreSDK.ObjectControl(
                    AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_QUEUE, queueIds[0],
                    AnyChatObjectDefine.ANYCHAT_QUEUE_CTRL_USERENTER, 0, 0, 0,
                    0, "");
        } else {
            entity.CurrentQueueId = 0;
            // 进入队列的控制指令
            AnyChatCoreSDK.ObjectControl(
                    AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_QUEUE, 0,
                    AnyChatObjectDefine.ANYCHAT_QUEUE_CTRL_USERENTER, 0, 0, 0,
                    0, "");
        }
    }

    public interface AnyChat_UpdateQueueInfoCallBack {
        public void onUpdateQueueInfo(int dwObjectId);
    }

    public interface AnyChat_VideoResultCallBack {
        public void onAnyChat_VieoResult(int obj);
    }
}

这段代码是将官方Demo中的登陆和排队部分放到一块,调用之后可以直接实现登陆、排队功能

AnyChatBaseEvent接口:这个接口是AnyChat最重要的接口,用户登陆、退出、房间所在人数都是有这个接口来控制;

AnyChatObjectEvent接口:这个接口是用来接收客服对象的接口;

OnAnyChatVideoCallEvent接口:这个接口是接收呼叫信息的接口,AnyChat_VideoResultCallBack是我自定义的接口来处理后台服务器发送的服务请求

这部分变动需要将BussinessCenter类中的参数做些改动,当相对较小,待会再后面贴上源码

③下面是在Activity中的调用:

package com.bankeys.shield.activity;

import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.bairuitech.anychat.AnyChatCoreSDK;
import com.bairuitech.anychat.AnyChatObjectDefine;
import com.bairuitech.common.BaseMethod;
import com.bairuitech.main.AnyChat_Login;
import com.bairuitech.main.AnyChat_Login.AnyChat_GetFunRoomCallBack;
import com.bairuitech.main.AnyChat_Login.AnyChat_LoginCallBack;
import com.bairuitech.main.AnyChat_Login.AnyChat_UpdateQueueInfoCallBack;
import com.bairuitech.main.AnyChat_Login.AnyChat_VideoResultCallBack;
import com.bairuitech.main.AnyChat_Login.LoginStatus;
import com.bairuitech.main.BussinessCenter;
import com.bairuitech.main.QueueInfoEntity;
import com.bankeys.base.ShieldBaseActivity;
import com.bankeys.shield.R;
import com.bankeys.shield.util.BksUtils;
import com.bankeys.shield.view.AlerDialogTools;
import com.bankeys.util.LogUtil;

public class VideoQueueActivity extends ShieldBaseActivity {
    private Button quickButton;
    private TextView showTextView;
    private TextView timeshow;
    private final int TIME_UPDATE = 291; // Handler发送消息,队列人数的实时更新
    private AnyChat_Login login;
    private int USER_TYPE_ID; // 0代表是进入客户界面,2代表是接入座席界面
    private QueueInfoEntity entity;
    private Dialog mDialog;
    private String appCode;
    private String applyId;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_queue;
    }

    @Override
    protected void initLayout() {
        entity = QueueInfoEntity.getQueueInfoEntity();
        appCode = getIntent().getStringExtra(BksUtils.APPCODE);
        applyId = getIntent().getStringExtra(BksUtils.APPLYID);
        startLogin();
        initView();
    }

    @Override
    protected CharSequence setTitle() {
        return getResources().getString(R.string.remote_attestation);
    }

    private void initView() {
        int length = AnyChatCoreSDK.ObjectGetIntValue(AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_QUEUE,
                entity.CurrentQueueId, AnyChatObjectDefine.ANYCHAT_QUEUE_INFO_LENGTH);
        // 排在自己前面的人数
        int morder = AnyChatCoreSDK.ObjectGetIntValue(AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_QUEUE,
                entity.CurrentQueueId, AnyChatObjectDefine.ANYCHAT_QUEUE_INFO_BEFOREUSERNUM);
        showTextView = (TextView) findViewById(R.id.queue_show);
        showTextView.setText("当前排队人数共:" + length  + "人,您现在排在第 " + (morder + 1) + " 位");
        LogUtil.debug("");
        // 实时更新显示时间
        timeshow = (TextView) findViewById(R.id.queue_time);
        final Handler myhHandler = new Handler(new Handler.Callback() {

            @Override
            public boolean handleMessage(Message msg) {
                if (msg.what == TIME_UPDATE) {
                    int seconds = AnyChatCoreSDK.ObjectGetIntValue(
                            AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_QUEUE,
                            entity.CurrentQueueId,
                            AnyChatObjectDefine.ANYCHAT_QUEUE_INFO_WAITTIMESECOND);
                    timeshow.setText("您已等待了 " + BaseMethod.getTimeShowStringTwo(seconds));
                }
                return false;
            }
        });
        new Timer().schedule(new TimerTask() {

            @Override
            public void run() {
                myhHandler.sendEmptyMessage(TIME_UPDATE);
            }
        }, 0, 1000);

        quickButton = (Button) findViewById(R.id.queue_btn);
        quickButton.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                alertDialog();
            }
        });

    }

    private void startLogin() {
        login = new AnyChat_Login(this, BksUtils.getTermId(this), applyId);
        login.setAnyChat_LoginCallBack(new AnyChat_LoginCallBack() {

            @Override
            public void getLoginStatus(LoginStatus status, int dwUserId) {
                switch (status) {
                case Reconnection:
                case Waiting:
                    mDialog = AlerDialogTools.showWaitingDialog(VideoQueueActivity.this,
                            "正在登陆,请稍候", false);
                    mDialog.show();
                    break;
                case Success:
                    entity.userType = USER_TYPE_ID;
                    if (mDialog != null && mDialog.isShowing()) {
                        mDialog.dismiss();
                    }
                    break;
                case NoNet:
                default:
                    if (mDialog != null && mDialog.isShowing()) {
                        mDialog.dismiss();
                    }
                    break;
                }
            }
        });
        login.setAnyChat_GetFunRoom(new AnyChat_GetFunRoomCallBack() {

            @Override
            public void getAnyChat_GetFunRoom(List<Integer> list) {
                AnyChatCoreSDK.ObjectControl(AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_AREA, list.get(0),
                        AnyChatObjectDefine.ANYCHAT_AREA_CTRL_USERENTER, 0, 0, 0, 0, "");
                String termId = BksUtils.getTermId(VideoQueueActivity.this);
                try {
                    String s = termId.substring(termId.length() - 1,termId.length());
                    int ox = Integer.parseInt(s);
                    if(list.size() > 1){
                            entity.CurrentAreaId = list.get(ox / 2);
                    }else{
                        entity.CurrentAreaId = list.get(0); //营业厅ID
                    }
                } catch (Exception e) {
                    entity.CurrentAreaId = list.get(0); //营业厅ID
                }

            }
        });
        login.setUpdateCallBack(new AnyChat_UpdateQueueInfoCallBack() {

            @Override
            public void onUpdateQueueInfo(int dwObjectId) {
                dataChange(dwObjectId);
            }
        });
        login.setVideoCallBack(new AnyChat_VideoResultCallBack() {

            @Override
            public void onAnyChat_VieoResult(final int dwUserId) {
                Intent intent = new Intent(VideoQueueActivity.this, VideoCallActivity.class);
                intent.putExtra(BksUtils.APPLYID, applyId);
                intent.putExtra(BksUtils.APPCODE, appCode);
                startActivityForResult(intent, 0);
            }
        });
        login.loginAnyChat();
    }

    private void alertDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(VideoQueueActivity.this);
        builder.setMessage("您确定要退出当前排队吗?").setPositiveButton("确定", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                AnyChatCoreSDK.ObjectControl(AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_QUEUE,
                        entity.CurrentQueueId,
                        AnyChatObjectDefine.ANYCHAT_QUEUE_CTRL_USERLEAVE, 0, 0, 0, 0, "");
                finish();
            }
        }).setNegativeButton("取消", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {

            }
        }).create().show();
    }

    private void dataChange(int dwObjectId) {

        if (dwObjectId == entity.CurrentQueueId) {

            int length = AnyChatCoreSDK.ObjectGetIntValue(AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_QUEUE,
                    dwObjectId, AnyChatObjectDefine.ANYCHAT_QUEUE_INFO_LENGTH);
            int mbefore = AnyChatCoreSDK.ObjectGetIntValue(AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_QUEUE,
                    dwObjectId, AnyChatObjectDefine.ANYCHAT_QUEUE_INFO_BEFOREUSERNUM);
            showTextView.setText("当前排队人数共:" + length + "人,您现在排在第 " + (mbefore + 1) + " 位");
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        login.onDestroy();
        BussinessCenter.getBussinessCenter().realse();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        login.onRestart();
    }

    @Override
    protected void onActivityResult(int arg0, int arg1, Intent arg2) {
        // TODO Auto-generated method stub
        super.onActivityResult(arg0, arg1, arg2);
        if(arg1 == RESULT_OK){
            finish();
        }
    }

    @Override
    protected void onResume() {
        BussinessCenter.mContext = VideoQueueActivity.this;
        super.onResume();
    }

}

Activity调用可以根据具体场景做相应的调整,在此就不多说了。

④视频界面参考官方Demo,我只是稍加变动而已,就不在这里一一展示,如果需要项目源码可以给我留邮箱。

时间: 2024-11-05 11:35:45

AnyChatSDK 实现视频通话的相关文章

crosswalk 快速入门,利用WebRTC(html)开始开发视频通话

crosswalk 快速入门,利用WebRTC(html)开始开发视频通话 安装Python 从http://www.python.org/downloads/ 下载安装程序 安装完后,再添加到环境变量. 安装Oracle JDK 下载页面: http://www.oracle.com/technetwork/java/javase/downloads/ 选择要下载的Java版本(推荐Java 7). 选择一个JDK下载并接受许可协议. 一旦下载,运行安装程序. 安装Ant Ant:下载http

微信2.1 for Windows发布 微信群可多人语音或视频通话

5月31日,windows电脑版微信发布更新,微信2.1 for Windows带来最主要的功能是微信群可以多人语音或视频通话了,建个家庭群组,常年在外工作的家人也可以每天见面了,多亲切! 除了可以建立多人语音聊天外,还全新设计了聊天消息气泡.发送文件大小从25M提高到100M.优化内置浏览器,提升浏览体验. 小伙伴们赶紧去体验吧

freeSWITCH 视频通话

一,freeSWITCH安装 本实验基于CentOS 6 源码编译安装FreeSWITCH,详细安装过程见下: http://990487026.blog.51cto.com/10133282/1921010 二,配置FreeSWITCH,加载H26x模块 1,FreeSWITCH先处于关闭状态. 2,修改配置文件: [[email protected] ~]# vim ~/freeswitch/etc/freeswitch/vars.xml 将:   <X-PRE-PROCESS cmd=&quo

做移动端视频通话软件,大致看了下现有的开源软件(转)

转自:链接 要做一个移动端视频通话软件,大致看了下现有的开源软件 一) sipdroid1)架构sip协议栈使用JAVA实现,音频Codec使用skype的silk(Silk编解码是Skype向第三方开发人员和硬件制造商提供免版税认证(RF)的Silk宽带音频编码器)实现.NAT传输支持stun server.2)优缺点:NAT方面只支持STUN,无ICE框架,如需要完全实现P2P视频通话需要实现符合ICE标准的客户端,音频方面没看到AEC等技术,视频方面还不是太完善,目前只看到调用的是系统自带

iOS视频通话方案

现在iPhone4平台上实时音视频对话已取得初步成果.其间查阅了很多资料,感谢这些信息的提供者.继往开来,我写下此文.我只列出要点,具体编码以及平台移植各位自己去努力吧.照着下面的步骤,您一定能做出来的. 1,视频采集用iPhone4SDK里面的AVCaptureSession. 苹果官网有示例代码. 2,视频编码用ffmpeg,如要支持H264编码,还需引入x264库.ffmpeg和x264是两个不同的库,需要各自编译. 3,视频解码与播放可参看开源工程iFrameExtractor. 4,音

android 视频通话开启呼叫等待后,来第三方的视频通话,接通后通话时间一直显示为0,过几秒之后视频通话自己主动挂断

开启通话设置视频通话的"来电等待"; 步骤1:測试机和配合机A处于视频通话过程中; 步骤2:配合机B向測试机呼出视频电话; 步骤3:測试机接听配合机B的视频来电; 现象:视频通话过几秒之后自己主动断掉 找到文件alps/packages/apps/Phone/src/com/mediatek/phone/vt/VTInCallScreen.java, 找到函数internalAnswerVTCallPre(), 将例如以下两行: VTInCallScreenFlags.getInsta

Android的视频通话的Java代码

  最近学习Android平台下跨平台音视频通信开发,虽然网上有很多开源项目供我们参考学习,但音视频效果很一般,还有很多不稳定的因素,毕竟是开源嘛.在国内我找到了一个比较好音视频通信解决方案(百度下载官方Anychat for Android 的demo),该案例提供了纯Java语言接口供我们调用,随后我参照官方android demo程序和开发文档并结合自己的见解写了一个android音频通信软件,200行以内代码就搞定了(难以相信吧).其实我只是调用其相关API即可实现.以下是我自己写的Ja

imo free video calls and text(IMO免费视频通话)

插件介绍: 这是一款国际通用的即时通讯软件,专为企业团队内部打造的沟通平台,IMO为您提供了更安全,更稳定的办公沟通环境,极大地提高办公效率,提升执行力. 使用说明: 将imo free video calls and text(IMO免费视频通话)添加至chrome,并在扩展器中启动它. 功能介绍: 高质量的视频和语音通话组聊天的朋友,家人,室友和其他人分享照片和视频表达自己随意贴!使用SSL / TLS安全聊天,和加密的语音和视频通话也使用IMO在Android,iPhone和iPad避免短

WebRTC VideoEngine综合应用示例(一)——视频通话的基本流程(转)

本系列目前共三篇文章,后续还会更新 WebRTC VideoEngine综合应用示例(一)——视频通话的基本流程 WebRTC VideoEngine综合应用示例(二)——集成OPENH264编解码器 WebRTC VideoEngine综合应用示例(三)——集成X264编码和ffmpeg解码 WebRTC技术的出现改变了传统即时通信的现状,它是一套开源的旨在建立浏览器端对端的通信标准的技术,支持浏览器平台,使用P2P架构.WebRTC所采用的技术都是当前VoIP先进的技术,如内部所采用的音频引