kcpac kcpac - 5 months ago 201
Objective-C Question

Create a thumbnail or image of an AVPlayer at current time

I have implemented an

AVPlayer
and i want to take an image or thumbnail when clicking on a toolbar button and open in a new
UIViewController
with
UIImageView
. The image should be scaled exactly like the
AVPlayer
.
The
segue
is already working, i just have to implement that i get the image at the current play time.

Thanks!

Answer
AVAsset *asset = [AVAsset assetWithURL:sourceURL];
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
CMTime time = CMTimeMake(1, 1);
CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NULL error:NULL];
UIImage *thumbnail = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);  // CGImageRef won't be released by ARC