计算通话时长
本文档描述了如何通过配置来计算通话时长。
实现流程
如需计算通话时长,请执行以下操作:
-
将
ZegoCallDurationConfig
的isVisible
属性设置为true
(显示当前通话计时器(默认值))。 -
开发者可以通过
durationConfig.onDurationUpdate
获取通话时长(参考以下代码)。
Note
如果需要实现定时自动挂断的功能,则可以使用以下方法挂断通话。
- 基本通话:调用
CallActivity
的finish
方法。 - 携带邀请的通话:
ZegoUIKitPrebuiltCallService
的endCall
方法。
基本通话
携带邀请的通话
long appID = yourAppID;
String appSign = yourAppSign;
String userID = yourUserID;
String userName = yourUserName;
ZegoUIKitPrebuiltCallConfig config = ZegoUIKitPrebuiltCallConfig.oneOnOneVideoCall();
config.durationConfig = new ZegoCallDurationConfig();
config.durationConfig.isVisible = true;
config.durationConfig.durationUpdateListener = new DurationUpdateListener() {
@Override
public void onDurationUpdate(long seconds) {
Log.d(TAG, "onDurationUpdate() called with: seconds = [" + seconds + "]");
if (seconds == 30) {
finish();
}
}
};
ZegoUIKitPrebuiltCallFragment fragment = ZegoUIKitPrebuiltCallFragment.newInstance(appID, appSign, userID,userName, callID, config);
1
long appID = yourAppID;
String appSign = yourAppSign;
String userID = yourUserID;
String userName = yourUserName;
ZegoUIKitPrebuiltCallInvitationConfig callInvitationConfig = new ZegoUIKitPrebuiltCallInvitationConfig();
callInvitationConfig.provider = new ZegoUIKitPrebuiltCallConfigProvider() {
@Override
public ZegoUIKitPrebuiltCallConfig requireConfig(ZegoCallInvitationData invitationData) {
ZegoUIKitPrebuiltCallConfig config = null;
boolean isVideoCall = invitationData.type == ZegoInvitationType.VIDEO_CALL.getValue();
boolean isGroupCall = invitationData.invitees.size() > 1;
if (isVideoCall && isGroupCall) {
config = ZegoUIKitPrebuiltCallConfig.groupVideoCall();
} else if (!isVideoCall && isGroupCall) {
config = ZegoUIKitPrebuiltCallConfig.groupVoiceCall();
} else if (!isVideoCall) {
config = ZegoUIKitPrebuiltCallConfig.oneOnOneVoiceCall();
} else {
config = ZegoUIKitPrebuiltCallConfig.oneOnOneVideoCall();
}
config.durationConfig = new ZegoCallDurationConfig();
config.durationConfig.isVisible = true;
config.durationConfig.durationUpdateListener = new DurationUpdateListener() {
@Override
public void onDurationUpdate(long seconds) {
Log.d(TAG, "onDurationUpdate() called with: seconds = [" + seconds + "]");
if (seconds == 60*5) {
ZegoUIKitPrebuiltCallService.endCall();
}
}
};
return config;
}
};
ZegoUIKitPrebuiltCallService.init(getApplication(), appID, appSign, userID, userName,callInvitationConfig);
1