1

every one i am trying to get the video frame or thumbnail from a video url but not succeeding in it, here is my code

- (void)viewDidLoad {
    thumbnailimg = [[UIImageView alloc]init];
    movie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=ec9KXrpYvzk"]];
    //UIImage *singleFrameImage = [movie thumbnailImageAtTime:10 
                                                 //timeOption:MPMovieTimeOptionExact];
    //thumbnailimg.image = singleFrameImage;

    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    [nc addObserver:self selector:@selector(handleThumbnailImageRequestFinishNotification:) 
               name:MPMoviePlayerThumbnailImageRequestDidFinishNotification
             object:movie];
    NSNumber * time =[NSNumber numberWithInt:10];


    NSArray *times = [NSArray arrayWithObjects:time,nil];
    [movie requestThumbnailImagesAtTimes:times timeOption:MPMovieTimeOptionExact];



    [super viewDidLoad];
}


-(void)handleThumbnailImageRequestFinishNotification:(NSNotification*)note
{

        NSDictionary *userinfo = [note userInfo];
        NSMutableDictionary *event = [NSMutableDictionary dictionary];
        NSError* value = [userinfo objectForKey:MPMoviePlayerThumbnailErrorKey];
        if (value!=nil)
        {

            [event setObject:[value description] forKey:@"error"];
        }
        else 
        {

            UIImage *image = [userinfo valueForKey:MPMoviePlayerThumbnailImageKey];
            thumbnailimg.image = image;

        }
        [event setObject:[userinfo valueForKey:MPMoviePlayerThumbnailTimeKey] forKey:@"time"];


}

even the handleThumbnailImageRequestFinishNotification is not firing, plz. tell me what i am doing wrong and how to correct it, thanx in advance, Regards Saad

Saad Umar
  • 604
  • 1
  • 8
  • 17

2 Answers2

1

It's not possible to read videos from YouTube with a MPMoviePlayerController try to use an other video (from a m3u8 playlist or MP4 file).

Julien
  • 963
  • 5
  • 8
  • Thanx Julien but i have you tube video links and my requirement is that i have to display video title plus its thumbnail in a table view cell n when user tap it i will play the video, so plz. tell me if there is any work around for this – Saad Umar Mar 01 '12 at 10:20
  • Take a look to the YouTube Web Services you may find a solution. https://developers.google.com/youtube/2.0/developers_guide_jsonc?hl=fr#Retrieving_Playlist_Contents – Julien Mar 02 '12 at 10:49
0

Just wanted to tell that times should be provided as float, not int. Replacing:

NSNumber * time =[NSNumber numberWithInt:10];

with:

NSNumber * time =[NSNumber numberWithFloat:10.0f];

Will maybe fix something.

Similar answer: https://stackoverflow.com/a/17870972

Community
  • 1
  • 1
Johann
  • 146
  • 9