ios7私は参考のためにこれを使用しています:Getting thumbnail from a video url or data in IPhone SDK生成サムネイル -
方法ではなくAVFoundationのMPMoviePlayerControllerクラスを使用している、と私はそれにも利用したいと考える人々が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 Iは、(参照としてthis questionを使用して)、サムネイル画像要求の通知を作成する方法を考え出しました。しかし、このメソッドはメインスレッドから非同期で動作するので、通知ハンドラメソッドは呼び出されないようです。
これは私が今持っているものです。
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];
そして、私のハンドラ・メソッド:
-(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];
}
しかし、ハンドラが呼び出されることは決してありません(またはそれが表示されます)。
作品、ありがとう。 – c0d3Junk13
@ c0d3Junk13あなたは大歓迎です:) – sankalp