WebRTC Swift RemoteStream无法渲染

问题描述 投票:0回答:1

我已经通过整个出口创建了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)
    }
}

报价后->回答->并且对等状态为已连接。仅本地视频正在渲染。远程视频未呈现。enter image description here

ios swift webrtc rendering
1个回答
0
投票

我最近在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)
© www.soinside.com 2019 - 2024. All rights reserved.