主頁(yè) > 服務(wù)與支持 > 開(kāi)發(fā)平臺(tái) > 客戶端SDK參考 > Android Native SDK > 音視頻呼叫 保持和恢復(fù)視頻通話
更新時(shí)間:2019-11-20
用戶可以將正在進(jìn)行的視頻通話保持,待需要的時(shí)候再恢復(fù)通話,能減少撥號(hào)次數(shù),使用更方便。
保持和恢復(fù)視頻通話,與“保持和恢復(fù)音頻通話”流程基本相同,不同在于通話被保持時(shí),視頻將會(huì)自動(dòng)被關(guān)閉,恢復(fù)時(shí),視頻將會(huì)自動(dòng)打開(kāi)。
視頻通話已建立,主被叫正在通話中。
保持通話
通話中,主被叫雙方均可以發(fā)起保持通話操作。
當(dāng)前服務(wù)器暫不支持視頻通話保持,需要先移除視頻窗口,轉(zhuǎn)換為語(yǔ)音通話后再保持通話。
//Java code public boolean delVideo() { int result = tsdkCall.delVideo(); if (result != 0) { LogUtil.e(TAG, "delVideo return failed, result = " + result); return false; } setCallStatus(CallConstant.CallStatus.AUDIO_CALLING); return true; } |
代碼示例:
//Java code public void onEvtCloseVideoInd(TsdkCall call){ if (null == call) { Log.e(TAG, "onCallDelVideo tupCall is null"); return; } Session callSession = getCallSessionByCallID(call.getCallInfo().getCallId()); if (callSession == null) { Log.e(TAG, "call session obj is null"); return; } callSession.setCallStatus(CallConstant.CallStatus.AUDIO_CALLING); //Clear video data VideoMgr.getInstance().clearCallVideo(); if (null != mCallNotification) { CallInfo callInfo = getCallInfo(call); mCallNotification.onCallEventNotify(CallConstant.CallEvent.CLOSE_VIDEO, callInfo); } if (callSession.isVideoHold()) { callSession.holdCall(); } } |
恢復(fù)通話
保持通話發(fā)起方才可進(jìn)行恢復(fù)通話操作。
恢復(fù)通話可能由于網(wǎng)絡(luò)側(cè)極低概率的沖突或異常,導(dǎo)致用戶恢復(fù)通話失敗,此時(shí)SDK通過(guò)TsdkNotify對(duì)象中的onEvtUnholdFailed() 向UI上報(bào)取消保持通話失敗事件,并自動(dòng)掛斷通話。
//Java code TsdkVideoWndInfo localWndInfo = new TsdkVideoWndInfo(); localWndInfo.setVideoWndType(TsdkVideoWndType.TSDK_E_VIDEO_WND_LOCAL); localWndInfo.setRender(ViERenderer.getIndexOfSurface(localVideoView)); localWndInfo.setDisplayMode(TsdkVideoWndDisplayMode.TSDK_E_VIDEO_WND_DISPLAY_FULL); TsdkVideoWndInfo remoteWndInfo = new TsdkVideoWndInfo(); remoteWndInfo.setVideoWndType(TsdkVideoWndType.TSDK_E_VIDEO_WND_REMOTE); remoteWndInfo.setRender(ViERenderer.getIndexOfSurface(remoteVideoView)); remoteWndInfo.setDisplayMode(TsdkVideoWndDisplayMode.TSDK_E_VIDEO_WND_DISPLAY_CUT); List<TsdkVideoWndInfo> list = new ArrayList<>(); list.add(localWndInfo); list.add(remoteWndInfo); TsdkManager.getInstance().getCallManager().getCallByCallId(callId).setVideoWindow(list); |
//Java code public boolean addVideo() { initVideoWindow(); int result = tsdkCall.addVideo(); if (result != 0) { LogUtil.e(TAG, "addVideo return failed, result = " + result); return false; } setCallStatus(CallConstant.CallStatus.VIDEO_CALLING); return true; } |
//Java code public void onEvtOpenVideoReq(TsdkCall call, TsdkVideoOrientation orientType){ Log.i(TAG, "onCallAddVideo"); if (null == call) { Log.e(TAG, "onCallAddVideo tupCall is null"); return; } Session callSession = getCallSessionByCallID(call.getCallInfo().getCallId()); if (callSession == null) { Log.e(TAG, "call session obj is null"); return; } CallConstant.CallStatus callStatus = callSession.getCallStatus(); boolean isSupportVideo = isSupportVideo(); if ((!isSupportVideo) || (CallConstant.CallStatus.AUDIO_CALLING != callStatus)) { callSession.rejectAddVideo(); return; } mCallNotification.onCallEventNotify(CallConstant.CallEvent.RECEIVED_REMOTE_ADD_VIDEO_REQUEST, null); } |
只有被請(qǐng)求方用戶接受時(shí),才需要此步驟。
若用戶長(zhǎng)時(shí)間沒(méi)有響應(yīng),被請(qǐng)求端應(yīng)用程序應(yīng)該自動(dòng)拒絕轉(zhuǎn)視頻的請(qǐng)求。建議時(shí)間為45s。
參數(shù)“isAccept”表示是否接受::“true”為同意,“false”為拒絕。
//Java code public boolean acceptAddVideo() { initVideoWindow(); int result = tsdkCall.replyAddVideo(true); if (result != 0) { LogUtil.e(TAG, "replyAddVideo(accept) return failed, result = " + result); return false; } return true; } |
代碼示例:
//Java code public void onEvtOpenVideoInd(TsdkCall call){ int isVideo = call.getCallInfo().getIsVideoCall(); // 1:video, 0: audio int callId = call.getCallInfo().getCallId(); Log.i(TAG, "isVideo: " + isVideo + "callId: " + callId); Session callSession = getCallSessionByCallID(callId); if (callSession == null) { return; } CallInfo callInfo = getCallInfo(call);//audio --> video success Log.i(TAG, "Upgrade To Video Call"); VideoMgr.getInstance().setVideoOrient(callId, CallConstant.FRONT_CAMERA); callSession.setCallStatus(CallConstant.CallStatus.VIDEO_CALLING); mCallNotification.onCallEventNotify(CallConstant.CallEvent.OPEN_VIDEO, callInfo); } |
//Java code public void onEvtRefuseOpenVideoInd(TsdkCall call){ VideoMgr.getInstance().clearCallVideo(); Session callSession = getCallSessionByCallID(call.getCallInfo().getCallId()); callSession.setCallStatus(CallConstant.CallStatus.AUDIO_CALLING); CallInfo callInfo = getCallInfo(call); mCallNotification.onCallEventNotify(CallConstant.CallEvent.REMOTE_REFUSE_ADD_VIDEO_SREQUEST, callInfo); } |
因通話雙方均可以在本端處于通話態(tài)發(fā)起保持操作,即通話可能會(huì)處于雙向保持態(tài),在任一保持方發(fā)起恢復(fù)通話時(shí),僅能恢復(fù)本端通話狀態(tài),不會(huì)恢復(fù)對(duì)端的通話狀態(tài)。視頻通話雙向保持中任一方先恢復(fù)通話,不會(huì)自動(dòng)打開(kāi)視頻。