Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerating thumbnail from video - ios7
    primarykey
    data
    text
    <p>I am using this for reference: <a href="https://stackoverflow.com/a/6027285/1145339" title="Getting thumbnail from a video url or data in IPhone SDK">Getting thumbnail from a video url or data in IPhone SDK</a></p> <p>The method is using the MPMoviePlayerController class instead of the AVFoundation, and I think I want to use that as well because the people said that MPMoviePlayer way is faster than the AVFoundation way. </p> <p>The problem is, the method used to create the thumbnails, <code>[player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame]</code> is deprecated in iOS 7.0.</p> <p>By looking at the apple docs, the remaining supported ways to create thumbnails are by the methods <code>(void)requestThumbnailImagesAtTimes:(NSArray *)playbackTimes timeOption:(MPMovieTimeOption)option</code> and <code>(void)cancelAllThumbnailImageRequests</code>. But, as the method signatures dictate, these methods return nothing. So how do I access the <code>UIImage</code> thumbnail created by these methods?</p> <p>If it helps, this is what I have so far in terms of code:</p> <pre><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 = ??? </code></pre> <p>How do I get a UIImage reference to the thumbnail?</p> <p><strong>EDIT</strong> I figured out how to create a notification for the thumbnail image request (using <a href="https://stackoverflow.com/questions/14297726/cant-get-multiple-images-from-video-using-mpmovieplayercontroller-osstatus-12" title="Can&#39;t get multiple images from video using MPMoviePlayerController.">this question</a> as reference). However, I realise that this method works asynchronously from the main thread, and so my notification handler method doesn't seem to ever be called.</p> <p>This is what I have now.</p> <pre><code> 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]; </code></pre> <p>And then my handler method:</p> <pre><code>-(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]; } </code></pre> <p>But the handler never gets called (or so it appears).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload