我在将音频和视频从WebRTC集成到SwiftUI视图时遇到问题。 我试图用UIViewRepresentable来做到这一点,但发现一个错误。关于音频流我不知道。 My SwiftUI 视图:
if showingVideo {
//MARK: SHOW VIDEO, AND TURN ON AUDIO
} else {
}
我尝试使用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
}
答案是做这样的事情
@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
}
渲染远程视频的位置
func renderRemoteVideo(to renderer: RTCVideoRenderer) {
self.remoteVideoTrack?.add(renderer)
}
远程视频轨道是RTCVideoTrack。