1

我有一个应用程序,我可以在其中拍摄视频,然后将其与其他一些数据一起存储在核心数据中。它存储为可转换和“存储在外部记录文件中”。我将视频剪辑放入一个名为movie的对象中;

(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
     movie = [info objectForKey:UIImagePickerControllerEditedImage];

我卡住的地方是从电影中获取缩略图。使用MPMoviePlayerController我必须有一个 URL,但电影还没有存储在任何地方。另外,从核心数据中找到 URL 也是一个谜。

我可以在这里找到的最接近的帮助是从 iPhone SDK 中的视频 url 或数据中获取缩略图。但我被 URL 问题所困扰。

我将它保存到这样的核心数据中;

     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"];

如果有人可以给我指点,我将不胜感激。

4

3 回答 3

2

我在我的应用程序中这样使用

- (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);
}

像这样使用

imageView.image = [self imageFromMovie:fileURL atTime:10.0];
于 2013-06-27T11:20:51.607 回答
1

您可以像这样获取您的电影 URL,然后使用此 URL 使用 MPMoviePlayerController 获取缩略图。

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
     NSURL * movieURL = [info valueForKey:UIImagePickerControllerMediaURL] ;
     . .. .
     .. .. 
 }
于 2013-06-27T11:09:59.320 回答
1

要从电影中获取缩略图...

- (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];
 }
}
于 2013-06-27T11:14:57.623 回答