如何将流数据发送到UIView

时间:2019-07-12 14:25:46

标签: swift webrtc

我有两个类,WebRTCParent,它处理所有视频内容。并获得最终结果的parentUnitViewController。

class WebRTCParent: NSObject {}

class ParentUnitViewController: UIViewController {
    @IBOutlet weak var remoteView: UIView!
    let webRTCParent = WebRTCParent()
}

从对方接收视频时,此功能称为:

func peerConnection(_ peerConnection: RTCPeerConnection, didAdd stream: RTCMediaStream) {
        print("peerConnection did add stream")

        if (stream.audioTracks.count > 1) {
            print("Weird-looking stream: " + stream.description)
            return
        }

        let audioSession = AVAudioSession.sharedInstance()

        do {

            try audioSession.overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)
        } catch let error as NSError {
            print("audioSession error: \(error.localizedDescription)")
        }

        if (stream.videoTracks.count == 1) {
            print("media stream ontvangen met video")

            self.remoteVideoTrack = stream.videoTracks[0]
            self.remoteVideoTrack?.isEnabled = true


            self.delegate?.webRTCParent(self, remoteVideo: self.remoteVideoTrack!)

        }

    } 

到目前为止,还不错,但是如何将RTCMediaStream添加到视图中?我已经尝试过与委托,但似乎在几秒钟内关闭流。

代表可以吗?还是我应该怎么做?

0 个答案:

没有答案