1

I am a newbie in iOS.I want to show a video thumbnail in image view such that by clicking a Button it should open a gallery and by selecting a video it should display the video thumbnail...... please help me...

vinoad vinu
  • 225
  • 1
  • 2
  • 8

2 Answers2

1

There are videos and images that stored on photo library, firstly you want to get all videos from the library, prior to iOS 8, this post shows you how to fetch pictures using AssetsLibrary library. You can filter videos out when doing it, then you get an ALAsset, which can represent a image or video, suppose when you select a video, you get a ALAsset named asset, using the below function will get you a thumbnail image for that video.

If you use ALAsset.

UIImage *thumbnail = [UIImage imageWithCGImage:[asset thumbnail]];

For iOS 8, apple introduces a new Photos library,you can fetch all videos from the library as above, a video or images is represented by PHAsset, suppose you have a PHAsset ivar named asset, you can use the following method to get a UIImage from this asset. Take a look at requestImageForAsset:targetSize:contentMode:options:resultHandler:, you can set the target size to the size of the thumb image you want,in the resultHandler,you get the UIImage.

Community
  • 1
  • 1
gabbler
  • 13,626
  • 4
  • 32
  • 44
0

I am using below code to get thumbnail of video which is downloaded in document directory,

- (UIImage *)thumbnailFromVideoAtURL:(NSURL *)url
{
   AVURLAsset *aImgAsset = [[AVURLAsset alloc] initWithURL:url options:nil];
   AVAssetImageGenerator *aImgGenerator = [[AVAssetImageGenerator alloc] aImgAsset];
   aImgGenerator.appliesPreferredTrackTransform = YES;
   NSError *err = NULL;
   CMTime time = CMTimeMake(1, 2);
   CGImageRef aImgRef = [aImgGenerator copyCGImageAtTime:time actualTime:NULL error:&err];
   UIImage *aImgThumb = [[UIImage alloc] initWithCGImage:aImgRef];

   return aImgThumb;
}
cjd
  • 549
  • 3
  • 11