简体   繁体   English

AVSampleBufferDisplayLayer:改变视频重力动画

[英]AVSampleBufferDisplayLayer: change videoGravity animated

In my project I am using AVSampleBufferDisplayLayer and AVPlayerLayer.在我的项目中,我使用 AVSampleBufferDisplayLayer 和 AVPlayerLayer。 Bot of them have similar interface and videoGravity property.它们的 Bot 具有相似的界面和 videoGravity 属性。 When I change AVPlayerLayer videoGravity property video is re-sized immediately with animation effect.当我更改 AVPlayerLayer videoGravity 属性时,视频会立即重新调整大小并具有动画效果。 With AVSampleBufferDisplayLayer videoGravity nothing happen till I change device orientation and then video is re-sized without animation.使用 AVSampleBufferDisplayLayer videoGravity,直到我改变设备方向,然后在没有动画的情况下重新调整视频大小后,才会发生任何事情。

How to change videoGravity of AVSampleBufferDisplayLayer to behave similar to the AVPlayerLayer?如何更改 AVSampleBufferDisplayLayer 的 videoGravity 以使其行为类似于 AVPlayerLayer?

The only solution I've found is to reinitialize the AVSampleBufferDisplayLayer for example:我发现的唯一解决方案是重新初始化 AVSampleBufferDisplayLayer 例如:

var displayBufferLayer: AVSampleBufferDisplayLayer?
...
func reinitBufferLayer(videoGravity: AVLayerVideoGravity) {
    displayBufferLayer?.flush()
    displayBufferLayer?.stopRequestingMediaData()
    displayBufferLayer?.removeFromSuperlayer()

    let bufferLayer = AVSampleBufferDisplayLayer()
    bufferLayer.frame = view.bounds
    bufferLayer.videoGravity = videoGravity // (i.e. .resizeAspectFill)
    bufferLayer.isOpaque = true
    view.layer.insertSublayer(bufferLayer, at: 0)

    self.displayBufferLayer = bufferLayer
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM