I'm currently running into an issue where I need to take a screenshot of UIView
which has a AVPlayerLayer
attached to it.
I read some Apple's documents for AVFoundation, and it suggests to use AVAssetImageGenerator
. However, I don't have access to AVPlayer
object.
I tried some solutions like
UIGraphicsBeginImageContextWithOptions(videoPlayerView.bounds.size, videoPlayerView.isOpaque, 0)
videoPlayerView.drawHierarchy(in: videoPlayerView.bounds, afterScreenUpdates: false)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
and
videoPlayerView.snapshotView(afterScreenUpdates: false)
and
videoPlayerView.layer.render(in: context)
but none of them work.
I also came across this Screenshot for AVPlayer and Video, it seems like the current only solution is using AVAssetImageGenerator
.
Can anyone help me to understand why?