- (void)displayThumbnail
{
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[self outputURL] options:nil];
AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
gen.appliesPreferredTrackTransform = YES;
CMTime time = CMTimeMakeWithSeconds(1, 30);
NSError *error = nil;
CMTime actualTime;
CGImageRef imageref = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];
UIImage *thumbnail = [[UIImage alloc] initWithCGImage:imageref];
CGImageRelease(imageref);
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
MainViewController *controller = [mainStoryboard instantiateViewControllerWithIdentifier:@"MainViewController"];
controller.imageView.image = thumbnail;
}
I'm attempting to display a thumbnail of a recorded video in another view controller, but nothing shows up. Am I missing something?
Solved it !
Credits to David and Dan :)
MainViewController.h
@property (weak, nonatomic) IBOutlet UIImageView *thumbnailAV;
MainViewController.m
AVURLAsset *asset1 = [[AVURLAsset alloc] initWithURL:[self outputURL] options:nil];
AVAssetImageGenerator *generate1 = [[AVAssetImageGenerator alloc] initWithAsset:asset1];
generate1.appliesPreferredTrackTransform = YES;
NSError *err = NULL;
CMTime time = CMTimeMake(1, 2);
CGImageRef oneRef = [generate1 copyCGImageAtTime:time actualTime:NULL error:&err];
UIImage *one = [[UIImage alloc] initWithCGImage:oneRef];
[self.thumbnailAV setImage:one];
[self.view setFrame:CGRectMake(0, 0, 320, 422)];
self.thumbnailAV.contentMode = UIViewContentModeScaleAspectFit;
}
THCaptureViewController.m
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
MainViewController *controller= [mainStoryboard instantiateViewControllerWithIdentifier:@"MainViewController"];
[self presentViewController:controller animated:YES completion:nil];
}