1

I have the code below:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
self.selectedMessage = [self.messages objectAtIndex:indexPath.row];
NSString *fileType = [self.selectedMessage objectForKey:@"fileType"];
if ([fileType isEqualToString:@"image"]) {
    [self performSegueWithIdentifier:@"showImage" sender:self];

} else {

    // File type is video
    PFFile *videoFile = [self.selectedMessage objectForKey:@"file"];
    NSURL *fileUrl = [NSURL URLWithString:videoFile.url];
    self.moviePlayer.contentURL = fileUrl;
    [self.moviePlayer prepareToPlay];
    [self.moviePlayer thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionNearestKeyFrame];

    // Add it to the view controller so we can see it
    [self.view addSubview:self.moviePlayer.view];
    [self.moviePlayer setFullscreen:YES animated:YES];
}

On the line that says:

[self.moviePlayer thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionNearestKeyFrame];

it gives me the error:

thumbnailImageAtTime:timeOption: is deprecated: first deprecated in iOS 7.0

If anyone could help fix this problem, it would be appreciated. Thank you!

SahilS
  • 396
  • 5
  • 7
user245590
  • 11
  • 1
  • 3
  • possible duplicate of [thumbnailImageAtTime: now deprecated - What's the alternative?](http://stackoverflow.com/questions/19105721/thumbnailimageattime-now-deprecated-whats-the-alternative) – Ben Lings Feb 24 '14 at 16:24

2 Answers2

3

Please see my answer to this same issue here ThumbnailImageAtTime Deprecated - What's the alternative

AVURLAsset *asset1 = [[AVURLAsset alloc] initWithURL:partOneUrl 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];
[_firstImage setImage:one];
_firstImage.contentMode = UIViewContentModeScaleAspectFit;

Within header file, please import

#import <AVFoundation/AVFoundation.h>

It works perfect and I've been able to call it from viewDidLoad, which was quicker than calling the deprecated thumbNailImageAtTime: from the viewDidAppear.

Hope this helps anyone else who had the same problem.

Community
  • 1
  • 1
Jim Tierney
  • 4,078
  • 3
  • 27
  • 48
0
AVURLAsset *asset1 = [[AVURLAsset alloc] initWithURL:partOneUrl 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];
[_firstImage setImage:one];
_firstImage.contentMode = UIViewContentModeScaleAspectFit;

Add AVFoundation and CoreMedia framework

#import <AVFoundation/AVFoundation.h>
#import <CoreMedia/CoreMedia.h>
SahilS
  • 396
  • 5
  • 7
  • I get confused with the time variable, how do I get a image at 1 sec in to the video, and how do I get an image 2 seconds in? – iqueqiorio Apr 11 '15 at 11:56