ich diese Referenz bin mit: Getting thumbnail from a video url or data in IPhone SDKGenerieren von Thumbnail von Video - ios7
Das Verfahren der MPMoviePlayerController Klasse wird anstelle des AVFoundation, und ich glaube, ich möchte, dass auch benutzen, weil die Leute sagten, dass MPMoviePlayer Weg ist schneller als der AVFoundation Weg.
Das Problem ist, das Verfahren verwendet, um die Vorschaubilder zu erstellen, wird [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame]
in iOS 7.0 veraltet.
Wenn Sie sich die Apple-Dokumente ansehen, sind die verbleibenden unterstützten Möglichkeiten zum Erstellen von Miniaturansichten die Methoden (void)requestThumbnailImagesAtTimes:(NSArray *)playbackTimes timeOption:(MPMovieTimeOption)option
und . Aber wie die Methodensignaturen vorschreiben, geben diese Methoden nichts zurück. Wie greife ich auf die Thumbnail , die durch diese Methoden erstellt wird?
Wenn es hilft, ist es das, was ich bisher in Form von Code haben:
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 = ???
Wie kann ich auf das Bild, um eine UIImage Referenz bekommen?
EDIT ich herausgefunden, wie eine Benachrichtigung für die Thumbnail-Bild Anfrage erstellen (this question als Referenz). Allerdings stelle ich fest, dass diese Methode asynchron von dem Hauptthread arbeitet, und so meine Benachrichtigungs-Handhabungs-Methode scheint nicht immer genannt werden.
Dies ist, was ich jetzt habe. meine Handler-Methode
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];
Und dann:
-(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];
}
Aber die Handler nie aufgerufen werden (oder so scheint es).
Werke, danke. – c0d3Junk13
@ c0d3Junk13 Sie sind herzlich willkommen :) – sankalp