Reputation: 475
I have an app where I can shoot a video and then store it in core-data with some other data. It's stored as Transformable and "Store in External Record File". I get the video clip into an object called movie like this;
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
movie = [info objectForKey:UIImagePickerControllerEditedImage];
Where I get stuck is to get a thumbnail from the movie. Using MPMoviePlayerController
I have to have an URL, but the movie isn't stored anywhere yet. Plus finding the URL from the core-data is a mystery as well.
The closest help I can find here is Getting a thumbnail from a video url or data in iPhone SDK . But I get caught out on the URL issue.
I am saving it to core-data like this;
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *newMedia = [NSEntityDescriptioninsertNewObjectForEntityForName:@"Media" inManagedObjectContext:context];
[newMedia setValue:@"Video Clip " forKey:@"title"];
[newMedia setValue:now forKey:@"date_time"];
[newMedia setValue:movie forKey:@"movie"];
[newMedia setValue:[self generateImage] forKey:@"frame"];
I would be grateful if there is someone out there that can give me a pointer.
Upvotes: 1
Views: 1809
Reputation: 5183
To get thumbnail from movie...
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
if ([[info objectForKey:@"UIImagePickerControllerMediaType"] rangeOfString:@"movie"].location!=NSNotFound)
{
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[info objectForKey:@"UIImagePickerControllerMediaURL"]];
theMovie.view.frame = self.view.bounds;
theMovie.controlStyle = MPMovieControlStyleNone;
theMovie.shouldAutoplay=NO;
UIImage *imgTemp = [theMovie thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionExact];
}
}
Upvotes: 1
Reputation: 20021
I used like this in my app
- (UIImage *)imageFromMovie:(NSURL *)movieURL atTime:(NSTimeInterval)time {
// set up the movie player
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc]
initWithContentURL:movieURL];
mp.shouldAutoplay = NO;
mp.initialPlaybackTime = time;
mp.currentPlaybackTime = time;
// get the thumbnail
UIImage *thumbnail = [mp thumbnailImageAtTime:time
timeOption:MPMovieTimeOptionNearestKeyFrame];
// clean up the movie player
[mp stop];
[mp release];
return(thumbnail);
}
used like
imageView.image = [self imageFromMovie:fileURL atTime:10.0];
Upvotes: 2
Reputation: 909
You can get your movie URL like this and then use this URL to get thumbnail using MPMoviePlayerController.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL * movieURL = [info valueForKey:UIImagePickerControllerMediaURL] ;
. .. .
.. ..
}
Upvotes: 1