我已经通过整个出口创建了RTCMTLVideoView。
@IBOutlet weak var otherEndVideoHolderView : RTCMTLVideoView!
并且从RTCPeerConnectionDelegate委托中收集了RTCMediaStream
func peerConnection(_ peerConnection: RTCPeerConnection, didAdd stream: RTCMediaStream) {
debugPrint("peerConnection did add stream")
if let video = stream.videoTracks.first{
self.remoteVideoTrack = video
self.delegate?.webRTCClient(self, didReceiveRemoteRender: video)
}
}
我最近在Webrtc上工作,并在collectionview单元上添加了远程流。您可以使用我的代码。
let stream = VideoCallViewController.arrRemoteStreams[indexPath.row]
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "RmoteVideoCollectionViewCell", for: indexPath) as! RmoteVideoCollectionViewCell
cell.contentView.subviews.forEach({ $0.removeFromSuperview() })
#if arch(arm64)
// Using metal (arm64 only)
let remoteRenderer = RTCMTLVideoView(frame: CGRect.init(x: 0, y: 0, width: 150, height: 150))
remoteRenderer.videoContentMode = .scaleAspectFit
#else
// Using OpenGLES for the rest
let remoteRenderer = RTCEAGLVideoView(frame: CGRect.init(x: 0, y: 0, width: 150, height: 150))
#endif
//set stream to cell
stream.videoTracks.first?.add(remoteRenderer)
//adding stream to cellview
cell.contentView.addSubview(remoteRenderer)