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,我只是稍加变动而已,就不在这里一一展示,如果需要项目源码可以给我留邮箱。