1

hi im very new to ios i have read books beginner books and intermediate books, i understand ios put there are certain things i cant get done. im trying to put a thumbnail image of a .mov video into a cell like the youtube app i figured out how to do the thumbnail into UIImageView

NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"e.mov" ofType:nil];
NSURL *videoURl = [[NSURL alloc ] initFileURLWithPath:videoPath];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURl options:nil];
AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generate.appliesPreferredTrackTransform = YES;
NSError *err = NULL;
CMTime time = CMTimeMake(0.0, 600);
CMTime actualTime;

CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:&actualTime error:&err];

UIImage *img = [[UIImage alloc] initWithCGImage:imgRef];
[self.myImageView setImage:img];

thats what i have done to get the thumbnail image to the UIImageView on a standard UIViewController, i just cant figure out how to do it in a UITableViewCell *cell;

I have 18 videos i want to display in the cells as thumbnails and once the cell is touched prepareForSegue: method is activated then it goes to the detailViewCOntroller

NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"e.mov" ofType:nil];

How do i make this a NSMutableArray and put it in

NSURL *videoURl = [[NSURL alloc ] initFileURLWithPath:videoPath];

and make it work in cells

basically i cant figure out how to display an array of videos as thumbnails in cells please help

Rajesh Loganathan
  • 11,129
  • 4
  • 78
  • 90

2 Answers2

0

Try this:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString *CellIdentifier = @"Cell";
   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier   forIndexPath:indexPath] ;

   AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoPath options:nil];
   AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
   CMTime time = CMTimeMake(1, 30);
   CGImageRef thumbImg = [generate copyCGImageAtTime:time actualTime:NULL error:&err];


   if (cell == nil)
   {
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
   }
   cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
   cell.imageView.image = [UIImage imageWithCGImage:thumbImg];
   return cell;
}
Rajesh Loganathan
  • 11,129
  • 4
  • 78
  • 90
0

Here it is... get screenshot first frame of the video

- (UIImage*)loadImage {

    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:vidURL options:nil];
    AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    NSError *err = NULL;
    CMTime time = CMTimeMake(1, 60);
    CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:NULL error:&err];
    NSLog(@"err==%@, imageRef==%@", err, imgRef);

    return [[UIImage alloc] initWithCGImage:imgRef];

}
Community
  • 1
  • 1
Mahe
  • 98
  • 1
  • 8