Generieren von Thumbnails von video - ios7

Ich bin mit diesem Referenz: Immer Miniaturansicht von video-url oder Daten, die im IPhone SDK

Ist die Methode mit dem MPMoviePlayerController-Klasse anstelle der AVFoundation, und ich denke, das ich verwenden möchte, dass als gut, weil die Leute sagten, dass MPMoviePlayer Weg ist schneller als die AVFoundation Weg.

Das problem ist, dass die Methode zum erstellen der thumbnails, [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame] ist veraltet in iOS 7.0.

Durch die Suche auf der apple-docs, die restlichen unterstützten Möglichkeiten, thumbnails zu erstellen sind, durch die Methoden (void)requestThumbnailImagesAtTimes:(NSArray *)playbackTimes timeOption:(MPMovieTimeOption)option und (void)cancelAllThumbnailImageRequests. Aber, wie die Signaturen vorschreiben, sind diese Methoden, die nichts zurückgeben. Also, wie greife ich auf die UIImage thumbnail erstellt von diese Methoden?

Wenn es hilft, das ist, was ich bisher an code:

    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 bekomme ich ein UIImage Verweis auf die Miniaturansicht?

BEARBEITEN
Ich herausgefunden, wie man erstellen Sie eine Benachrichtigung für das thumbnail-Bild auf Anfrage (mit diese Frage als Referenz). Allerdings merke ich, dass diese Methode arbeitet asynchron aus dem main-thread, und damit meine notification handler-Methode scheint nicht immer genannt werden.

Dies ist, was ich jetzt habe.

    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];

Dann mein handler-Methode:

-(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 der handler wird nie genannt (oder so es scheint).

InformationsquelleAutor plasmaTonic | 2013-10-14

Schreibe einen Kommentar