0

我可以使用MPMoviePlayerController. 该方法requestThumbnailImagesAtTimes让我可以多次输入数组以获取缩略图,但是在MPMoviePlayerThumbnailImageRequestDidFinishNotification我的时间数组中,我只能从第一次取回一个图像。如何在我的数组中获取其他时间请求的其他图像?

在我的viewDidLoad

[self.movieController requestThumbnailImagesAtTimes:self.timesArray timeOption:MPMovieTimeOptionExact];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPMoviePlayerThumbnailImageRequestDidFinishNotification:) name:MPMoviePlayerThumbnailImageRequestDidFinishNotification object:self.movieController];

通知:

-(void)MPMoviePlayerThumbnailImageRequestDidFinishNotification: (NSNotification*)note
{

NSDictionary * userInfo = [note userInfo];
UIImage *image = (UIImage *)[userInfo objectForKey:MPMoviePlayerThumbnailImageKey];
if(image!=NULL)
    [self.trippingBalls setImage:image];

}
4

2 回答 2

0

我最终通过将收到的每个 UIImage 添加到数组中来解决这个问题。

我在我的 MPMoviePlayerController 上添加了一个 UIGestureRecognizer,所以在每个点击方法上,我都将从我的 Notification 收到的 UIImage 添加到我的数组中。

敲击方法:

- (void)handleRollTap:(UITapGestureRecognizer *)sender
{
float time = [self.movieController currentPlaybackTime];
[self.timesMutableArray addObject:[NSNumber numberWithFloat:time]];
self.view.backgroundColor = [UIColor blueColor];

self.timesArrayToPass = [NSArray arrayWithArray:self.timesMutableArray];
[self.movieController requestThumbnailImagesAtTimes:self.timesArrayToPass timeOption:MPMovieTimeOptionExact];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPMoviePlayerThumbnailImageRequestDidFinishNotification:) name:MPMoviePlayerThumbnailImageRequestDidFinishNotification object:self.movieController];

[self.images addObject:self.image];

NSLog(@"%@", self.images);
}

通知:

-(void)MPMoviePlayerThumbnailImageRequestDidFinishNotification: (NSNotification*)note
{
   NSDictionary * userInfo = [note userInfo];
self.image = (UIImage *)[userInfo objectForKey:MPMoviePlayerThumbnailImageKey];
    [self.imageView setImage:self.image];
}
于 2015-02-09T20:28:47.893 回答
0

也许它会帮助你......

-(UIImage *)generateThumbImage : (NSString *)filepath
{
    NSURL *url = [NSURL fileURLWithPath:filepath];

    AVAsset *asset = [AVAsset assetWithURL:url];
    AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
    CMTime time = [asset duration];
    time.value = 0;
    CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NULL error:NULL];
    UIImage *thumbnail = [UIImage imageWithCGImage:imageRef];
    CGImageRelease(imageRef);  // CGImageRef won't be released by ARC

    return thumbnail;
}

time.value = 1000 //时间以毫秒为单位

于 2015-02-09T07:00:26.447 回答