0

我可以使用MPMoviePlayerController播放視頻。方法requestThumbnailImagesAtTimes可讓我放入多個數組以獲得縮略圖,但在MPMoviePlayerThumbnailImageRequestDidFinishNotification中,我只能從我的時間數組中第一次獲取一個圖像。我怎麼能得到我的陣列中其他時間請求的其他圖像?如何使用requestThumbnailImagesAtTimes獲取多個縮略圖圖像

在我viewDidLoad

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

通知:

+0

你看到了什麼,當你打印出來的用戶信息'NSDictionary'? – 2015-02-09 04:07:46

+0

@lindonfox 我得到的一個圖像(在我的陣列第一及時,其具有多個時間鍵)的縮略圖圖像數據: { MPMoviePlayerThumbnailImageKey =「尺寸{720,1280}取向0刻度1.000000 「; MPMoviePlayerThumbnailTimeKey =「1.4」; } – 2015-02-09 04:11:04

+1

[this method](https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/index.html#//apple_ref/occ/instm/MPMoviePlayerController/requestThumbnailImagesAtTimes:timeOption :) might成爲你需要使用的東西。對不起,我以前沒有處理過這個問題,但您可能需要使用此方法訪問它們。 – 2015-02-09 04:12:37

回答

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 //時間以毫秒爲單位

0

我最終通過將每個UIImage添加到數組中來解決此問題。

我在我的MPMoviePlayerController上添加了一個UIGestureRecognizer,所以在每個tap方法中,我將從我的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]; 
}