在iOS模拟器中单击视频文件的视频缩略图

时间:2014-10-16 12:04:24

标签: ios objective-c xcode video

我在画廊中有一个视频。点击它试图打开,但而不是我想在uiimageview中显示视频的缩略图。

1 个答案:

答案 0 :(得分:0)

AVURLAsset *asset;
if ([url isFileURL]) {
   asset = [[AVURLAsset alloc] initWithURL:url options:nil];
}
AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
gen.appliesPreferredTrackTransform = YES;
CMTime time = CMTimeMakeWithSeconds(0.0, 600);
NSError *error = nil;
CMTime actualTime;

CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];
UIImage *thumb = [[UIImage alloc] initWithCGImage:image];
UIImage *finalThumpnailImage = [HPLUtility createThumpnailImageFromTheImage:thumb]; //Resized image.
CGImageRelease(image);
return finalThumpnailImage;