theBrogrammer
theBrogrammer

Reputation: 23

Remote video stream is not being rendered to the UIView even though the IBOutlet is connected

I can't seem to get remote video stream to render properly to my UIView. I can hear the two participants but can't seem to render the video stream even though the IO.

Any ideas why? Here's my code:

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)

    }
}

Upvotes: 2

Views: 703

Answers (1)

Sidharth Sharma
Sidharth Sharma

Reputation: 405

From your code, I see you are assigning the UID to be 0. That means it will automatically generate a new UID for the remote view. You can set the UID to 0 to auto generate the local video stream if you'd like. However, for the remote stream, you need to grab the assigned UID of the remote stream which is provided in the callback method's parameter as the uid variable.

Also, you need to make sure that you are adding the delegate methods in an extension that adopts the AgoraRtcEngineDelegate protocol.

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)
        }
    }
}

Upvotes: 1

Related Questions