Group Group Group Group Group Group Group Group Group

Capture UIView contains AVPlayer

I am making video app and I want to capture view contains avplayer.
Are there any way to capture this view contains avplayer?

Hi and welcome to the forums @petrohalilov! You can try playing a video in a UIView with something like this,
let player = AVPlayer(url: video) // your video url
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = videoView.bounds

Edit: Sorry about the formatting. Not sure why the indentation is not working and or I must not be able to figure it out! :sweat_smile:

Hi gdelarosa.
Thanks for your reply.
I did like above. After that I want to capture UIView to image.
Are there any way to do this?

Hi @petrohalilov do you mean you want to create a thumbnail from the video? Or could you give me an example so we can better understand please?

Hi Gina.
I don’t want to create a thumbnail from the video.
I just want to render UIView to UIImage, The UIView contains video playing.
For example, when the UIView frame is CGRect(0, 0, 200, 200), the AVPlayerLayer frame is CGRect(50, 50, 100, 100). I want to render UIView to UIImage but AVPlayerLayer part is empty.

Thanks, @petrohalilov. Maybe try something like this:

let renderer = UIGraphicsImageRenderer(size: view.bounds.size)
let image = renderer.image { ctx in
    view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)