2

我似乎无法让远程视频流正确渲染到我的 UIView。我可以听到两个参与者的声音,但即使 IO 似乎也无法渲染视频流。

任何想法为什么?这是我的代码:

func rtcEngine(_ engine: AgoraRtcEngineKit, firstRemoteVideoDecodedOfUid uid:UInt, size:CGSize, elapsed:Int) {

    DispatchQueue.main.async {

        if (self.remoteVideo.isHidden) {
            self.remoteVideo.isHidden = false
        }

        self.agoraKit.muteLocalAudioStream(false)

        let videoCanvas = AgoraRtcVideoCanvas()
        videoCanvas.uid = 0
        videoCanvas.view = self.remoteVideo
        videoCanvas.renderMode = .adaptive
        self.agoraKit.setupRemoteVideo(videoCanvas)

    }
}
4

1 回答 1

1

从您的代码中,我看到您将 UID 分配为 0。这意味着它将自动为远程视图生成一个新的 UID。如果您愿意,可以将 UID 设置为 0 以自动生成本地视频流。但是,对于远程流,您需要获取在回调方法的参数中提供的远程流的分配 UID 作为 uid 变量。

此外,您需要确保在采用 AgoraRtcEngineDelegate 协议的扩展中添加委托方法。

extension VideoChatViewController: AgoraRtcEngineDelegate {
// Tutorial Step 5

    func rtcEngine(_ engine: AgoraRtcEngineKit, firstRemoteVideoDecodedOfUid uid:UInt, size:CGSize, elapsed:Int) {
        DispatchQueue.main.async {
            if (self.remoteVideo.isHidden) {
                self.remoteVideo.isHidden = false
            }
            self.agoraKit.muteLocalAudioStream(false)

            let videoCanvas = AgoraRtcVideoCanvas()
            videoCanvas.uid = uid
            videoCanvas.view = self.remoteVideo
            videoCanvas.renderMode = .adaptive
            self.agoraKit.setupRemoteVideo(videoCanvas)
        }
    }
}
于 2018-08-23T19:33:30.940 回答