简体   繁体   中英

WebRTC - iOS Swift - Remove video stream and set uiview to black

I'm implementing an app that retrieves a video stream using WebRTC (libjingle_peerconnection library). At some moment, the stream (RTCVideoTrack) could be removed. When this happens in the UIView (RTCEAGLVideoView) still show the last frame of the stream. I want to set that View to black. How can I do it?

For now I'm removing the stream with the following code, but as I said, last frame keeps showing on the view.

remoteVideoTrack.setEnabled(false) // RTCVideoTrack object
remoteVideoTrack.remove(videoView) // videoView is the RTCEAGLVideoView UI object
remotePeerConnection.close()

I encountered a similar issue. However, in may case a black view wasn't acceptable and I needed the renderer view to become completely transparent.

Since the video chat view controller in my case is displayed in a container, I was able to make the renderer last frame disappear by completely reloading the container.

This is the relevant code:

        // Kill renderer
    vcWebRtc?.willMove(toParent: nil)
    vcWebRtc?.view.removeFromSuperview()
    vcWebRtc?.removeFromParent()
    
    vcWebRtc = UIStoryboard.instance(from: .WebRTC).instantiateInitialViewController() as? WebRtcVC
    if vcWebRtc != nil{
        addChild(vcWebRtc!)
        viewWebRtcContainer.addSubview(vcWebRtc!.view)
        vcWebRtc!.view.frame = viewWebRtcContainer.bounds
        vcWebRtc?.didMove(toParent: self)
        vcWebRtc?.delegate = self}
        
    

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