In my project I am using AVSampleBufferDisplayLayer and AVPlayerLayer. Bot of them have similar interface and videoGravity property. When I change AVPlayerLayer videoGravity property video is re-sized immediately with animation effect. With AVSampleBufferDisplayLayer videoGravity nothing happen till I change device orientation and then video is re-sized without animation.
How to change videoGravity of AVSampleBufferDisplayLayer to behave similar to the AVPlayerLayer?
The only solution I've found is to reinitialize the AVSampleBufferDisplayLayer for example:
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
}
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.