2

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?

Breek
  • 1,431
  • 13
  • 24
  • 1
    you want a snapshot of UIView(with its subviews), which can be achieved by using **UIGraphicsBeginImageContextWithOptions**. but AVPlayerlayer as a subview, it's not possible. On the other hand, using **AVAssetImageGenerator**, you can easily get a **thumbimage** from a video file in a specific time (you must have access to AVAsset). Please clarify why you don't have access to AVPlayer object – Imrul Kayes Oct 01 '17 at 07:01

0 Answers0