简体   繁体   中英

SwiftUI WebRTC Audio and Video rendering

I have a problem with integrating Audio and Video from WebRTC to SwiftUI View. Im trying to do this with UIViewRepresentable, but catch an error. About audio streaming i have no idea. My SwiftUI View:

        if showingVideo {
            //MARK: SHOW VIDEO, AND TURN ON AUDIO

        } else {

        }

My try with using UIViewRepresentable

func makeUIView(context: Context) -> RTCEAGLVideoView  {
        self.remoteView.frame = CGRect(x: 20, y: 20, width: 200, height: 300)
        self.remoteView = self.video.remoteVideoView!
        return self.remoteView
    }

The answer is doing something like this

@ObservedObject var videoCallController: VideoCallController
func updateUIView(_ uiView: UIViewType, context: Context) {
    let remoteRenderer = RTCEAGLVideoView(frame: UIScreen.main.bounds)
    self.videoCallController.webRTCClient.renderRemoteVideo(to: remoteRenderer)

}
func makeUIView(context: Context) -> RTCEAGLVideoView {
    let remoteRenderer = RTCEAGLVideoView(frame: UIScreen.main.bounds)
    self.videoCallController.webRTCClient.renderRemoteVideo(to: remoteRenderer)
    return remoteRenderer
}

Where render remote video is

func renderRemoteVideo(to renderer: RTCVideoRenderer) {
    self.remoteVideoTrack?.add(renderer)
}

Remote video track is RTCVideoTrack.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM