Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDouglas Rogers
2,619 PointsthumbnailImageAtTime is deprecated in iOS7. Alternative?
I'm getting a warning that thumbnailImageAtTime is deprecated in iOS 7. Is there a work around. I found this on StackOverflow, but it seems less than elegant as a solution to replace a single method call: http://stackoverflow.com/questions/19105721/thumbnailimageattime-now-deprecated-whats-the-alternative
Here's the line:
[self.moviePlayer thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionNearestKeyFrame];
is there a better, cleaner/shorter/more elegant way to get around this? im assuming it's not just a simple thing or else it would be obvious.
6 Answers
Charlie Hield
4,767 PointsI got it to work using @aarondaub7's suggestion
Step 1. Add the AVFoundation.framework
in the build phases panel.
Step 2. Update InboxViewController.h
#import <AVFoundation/AVFoundation.h>
Step 3. Update InboxViewController.m after the "prepareToPlay" method.
AVAsset *videoThumbnail = [AVAsset assetWithURL:fileURL];
[AVAssetImageGenerator assetImageGeneratorWithAsset:videoThumbnail];
Apple Docs -- AVAssetImageGenerator
Jack Crane
2,745 PointsI'm getting a bit confused on how to add this in?
t rosenthal
2,081 PointsAmit, thank you for the pointer.
Jonathan Fernandez
8,325 PointsWait I'm still kind of confused. I have created the method in Inbox.m and declared it in the header but have no idea how to add it. Shown below is my code and I have commented the part where I'm trying to add it. Xcode won't take in self.moviePlayer.
<p>
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
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 thumbnailFromVideoAtURL:fileUrl]; //How do I add this??
// Add it to the view controller so we can see it.
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer setFullscreen:YES animated:YES];
}
}
</p>
Also how does just adding in: (from the comment of Charlie Hield)
<b> AVAsset *videoThumbnail = [AVAsset assetWithURL:fileURL];
[AVAssetImageGenerator assetImageGeneratorWithAsset:videoThumbnail]; </b>
after the "prepareToPlay" method differ from using the method from the stack flow link? Does it by default set the thumbnail capture time also at 0?
James Lin
4,601 Pointsjust place with
[self.moviePlayer requestThumbnailImagesAtTimes:@[@0] timeOption:MPMovieTimeOptionNearestKeyFrame];
Amit Bijlani
Treehouse Guest TeacherJack Crane If you click on the Stack overflow link it takes you to the answer. The answer is a method which takes in a URL
and returns a UIImage
which can be assigned to the image
property of a UIImageView
.
Aaron Daub
Courses Plus Student 207 PointsAaron Daub
Courses Plus Student 207 PointsThe SO suggested way of doing it is correct - you should be using AVAssetImageGenerator from now on.