1

我正在使用 webRTC 远程视频流并将远程会话附加到此:

@IBOutlet weak var remoteVideoElement: QBRTCRemoteVideoView!

我想要发生的是当用户点击上面的插座时,远程流会填满整个窗口。当用户再次点击它时,它将返回到它在布局中的正常位置。在大多数情况下,它工作正常,除了我无法保持远程视频流的正确纵横比或屏幕分辨率。有人可以帮我找出获得预期效果的正确方法吗?

这是我的代码:

var isExpanded = Bool()
var videoPlayerViewCenter = CGPoint()

override func viewDidLoad() {
        super.viewDidLoad()
        isExpanded = false

        let toggleFullScreen = UITapGestureRecognizer(target: self, action: #selector (self.toggleFullScreenRemoteVideo(sender:)))
        self.view.addGestureRecognizer(toggleFullScreen)
}

func toggleFullScreenRemoteVideo(sender: QBRTCRemoteVideoView) {
        if !isExpanded {
            // GO FULL SCREEN
            UIView.animate(withDuration: 0.8, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
                self.videoPlayerViewCenter = self.remoteVideoElement.center
                self.view.bringSubview(toFront: self.modalShadeBackground)
                self.view.bringSubview(toFront: self.remoteVideoElement)
                self.remoteVideoElement.frame = CGRect(x: 0, y: 0, width: self.view.frame.height, height: self.view.frame.width)
                self.remoteVideoElement.frame = AVMakeRect(aspectRatio: (self.remoteVideoElement.layer.preferredFrameSize()), insideRect: self.remoteVideoElement.frame)
                self.remoteVideoElement.contentMode = .scaleAspectFit
                self.remoteVideoElement.frame = UIScreen.main.bounds
                self.remoteVideoElement.center = self.view.center
                self.remoteVideoElement.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi / 2))
                self.remoteVideoElement.layoutSubviews()
            }, completion: nil)
        } else {
            // REVERT BACK TO ORIGINAL CONTRAINTS IN THE LAYOUT
            UIView.animate(withDuration: 0.8, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
                self.remoteVideoElement.transform = CGAffineTransform.identity
                self.remoteVideoElement.center = self.videoPlayerViewCenter
                self.view.sendSubview(toBack: self.remoteVideoElement)
                self.view.sendSubview(toBack: self.modalShadeBackground)
                self.remoteVideoElement.frame = AVMakeRect(aspectRatio: (self.remoteVideoElement.layer.preferredFrameSize()), insideRect: self.remoteVideoElement.frame)
                self.remoteVideoElement.layoutSubviews()
            }, completion: nil)
        }
        isExpanded = !isExpanded
    }
4

1 回答 1

3

我不确定,QBRTCRemoteVideoView但我通过获取视频图像的比例并将其转换为视频视图的矩形,解决了视频流的类似问题。基本上是这样的:

let xScale = maxImageDrawingArea.size.width / imageSize.width    
let yScale = maxImageDrawingArea.size.height / imageSize.height
let scaleFactor = xScale < yScale ? xScale : yScale;

然后通过

let height = maxImageDrawingArea.size.height * scaleFactor
let width = maxImageDrawingArea.size.width * scaleFactor

然后使用此高度和宽度在您的情况下绘制您的视频支架 remoteVideoElement

更新我进展如何;

祝你好运,

于 2017-06-08T12:15:24.900 回答