logo
On this page

Calculate call duration

This doc describes how to calculate the call duration through configuration.

To calculate call duration, do the following:

  1. Set the isVisible property of ZegoCallDurationConfig to display the current call timer (It is displayed by default).

  2. Assuming that the call duration is 5 minutes, the call will automatically end when the time is up (refer to the following code). You will be notified of the end of the call duration through durationConfig.onDurationUpdate. To end the call, you can call the finish method of your CallActivity (Basic call) or the endCall method of ZegoUIKitPrebuiltCallService(Call with invitation).

Basic call
Call with invitation
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
Copied!

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
Copied!

On this page

Back to top