首页 > 解决方案 > Sinch 不支持快速视频通话

问题描述

这是我的代码。我将此代码从目标 c 转换为 sinch 测试中的 swift` 提供 Objective-C 部分可能会有所帮助,但它不支持视频通话。当我接受通话音频工作正常。但视频没有发送到其他设备。如果有人有 swift 的示例代码,请帮助我,然后发送或尝试使用此代码修复它.. 谢谢

// MARK: - Load
override func viewDidLoad() {
    super.viewDidLoad()

    if call?.direction == SINCallDirection.incoming {
        self.callStateLabel.text = ""
        self.showButtons(EButtonsBar.kButtonsAnswerDecline)
        //audioController().startPlayingSoundFile(path(forSound: "incoming.wav"), loop: true)
    } else {
        self.callStateLabel.text = "calling..."
        self.showButtons(EButtonsBar.kButtonsHangup)
    }
    if  (call?.details.isVideoOffered)! {
        localVideoView.addSubview(videoController().localView())
        localVideoFullscreenGestureRecognizer.require(toFail: switchCameraGestureRecognizer)
        videoController().localView().addGestureRecognizer(localVideoFullscreenGestureRecognizer)
        videoController().remoteView().addGestureRecognizer(remoteVideoFullscreenGestureRecognizer)
    }
}

@IBAction func accept(sender: AnyObject) {
    call?.answer()

}

@IBAction func decline(sender: AnyObject) {
    call?.hangup()
    dismiss(animated: true, completion: nil)
}


@IBAction func hangup(sender: AnyObject) {
    call?.hangup()
    dismiss(animated: true, completion: nil)
}

func audioController() -> SINAudioController{
    return Global.client.audioController()

}

func videoController() -> SINVideoController {
    return Global.client.videoController()
}

标签: iosswiftvideosinch

解决方案


在视图控制器中添加 2 个视图。一种用于本地视频查看,另一种用于远程视频视频。将其设置为查看控制器的插座。我有一个有效的音频呼叫示例,我只是将这些东西添加到我的呼叫视图控制器中。

func videoController() -> SINVideoController {
    return appDeletgate.client.videoController()
}

在 viewdidload 中检查是否通过电话提供视频。

if call.details.isVideoOffered {

    localVideoView.addSubview(videoController().localView())
    //localVideoFullscreenGestureRecognizer.require(toFail: switchCameraGestureRecognizer)
    //videoController().localView().addGestureRecognizer(localVideoFullscreenGestureRecognizer)
    //videoController().remoteView().addGestureRecognizer(remoteVideoFullscreenGestureRecognizer)
}

添加此方法可在视图中添加远程视频。

func callDidAddVideoTrack(_ call: SINCall?) {
    remoteVideoView.addSubview(videoController().remoteView())
}

还要确保将这 2 个键添加到 info.plist

<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) need to access your camera for video call.</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) uses the Microphone for calling</string>

这就是我所说的。

let call: SINCall? = self.callClient().callUserVideo(withId: recipientName) //self.callClient().callUser(withId: recipientName)
let callVC  = mainStoryBoard.instantiateViewController(withIdentifier: "CallVC") as! CallVC
callVC.call = call
self.navigationController?.pushViewController(callVC, animated: true)

推荐阅读