我使用此以供參考:Getting thumbnail from a video url or data in IPhone SDK生成縮略圖 - ios7
的方法是使用的MPMoviePlayerController類而不是AVFoundation,我想我要使用,以及因爲人說MPMoviePlayer方式比AVFoundation的方式更快。
的問題是,用於創建縮略圖的方法中,[player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame]
在IOS 7.0已棄用。
通過查看蘋果文檔,其餘支持的創建縮略圖的方法是通過方法(void)requestThumbnailImagesAtTimes:(NSArray *)playbackTimes timeOption:(MPMovieTimeOption)option
和(void)cancelAllThumbnailImageRequests
。但是,隨着方法簽名的規定,這些方法什麼都不會返回。那麼如何訪問這些方法創建的UIImage
縮略圖?
如果有幫助,這是我到目前爲止在代碼方面:
self.videoURL = info[UIImagePickerControllerMediaURL];
NSData *videoData = [NSData dataWithContentsOfURL:self.videoURL];
//Create thumbnail image
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:self.videoURL];
[player requestThumbnailImagesAtTimes:@[@1] timeOption:MPMovieTimeOptionNearestKeyFrame];
//UIImage *thumbnail = ???
我如何獲得一個UIImage參考縮略圖?
EDIT 我想出如何創建用於縮略圖圖像請求(使用this question作爲參考)的通知。但是,我意識到這種方法與主線程異步工作,所以我的通知處理程序方法似乎永遠不會被調用。
這是我現在有。
-(void)handleThumbnailImageRequestFinishNotification:(NSNotification*)notification
{
NSDictionary *userinfo = [notification userInfo];
NSError* value = [userinfo objectForKey:MPMoviePlayerThumbnailErrorKey];
if (value != nil)
{
NSLog(@"Error creating video thumbnail image. Details: %@", [value debugDescription]);
}
else
{
UIImage *thumbnail = [userinfo valueForKey:MPMoviePlayerThumbnailImageKey];
}
但處理程序不會被調用(或因此纔出現):
self.videoURL = info[UIImagePickerControllerMediaURL];
NSData *videoData = [NSData dataWithContentsOfURL:self.videoURL];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:self.videoURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleThumbnailImageRequestFinishNotification:) name:MPMoviePlayerThumbnailImageRequestDidFinishNotification object:player];
[player requestThumbnailImagesAtTimes:@[@1] timeOption:MPMovieTimeOptionNearestKeyFrame];
然後我的處理方法。
作品,謝謝。 – c0d3Junk13
@ c0d3Junk13歡迎您:) – sankalp