2012-03-01 55 views
1
获得视频缩略图(帧)

每一个我试图得到一个视频网址的视频帧或缩略图,但它没有成功,这里是我的代码iPhone开发从的MPMoviePlayerController

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


} 

连handleThumbnailImageRequestFinishNotification是不开火,plz。告诉我我做错了什么,以及如何纠正它,事先thanx,Regards Saad

回答

1

从MPMoviePlayerController尝试使用其他视频(从m3u8播放列表或MP4文件)中读取YouTube视频是不可能的。

+0

感谢名单朱利安,但我有你管的视频链接,我的要求是,我有一个表格视图单元格中显示视频标题以及其缩略图N将用户点击它,我将播放视频,所以PLZ。告诉我是否有任何解决此问题的方法 – 2012-03-01 10:20:19

+0

查看YouTube Web Services,您可能会找到解决方案。 https://developers.google.com/youtube/2.0/developers_guide_jsonc?hl=fr#Retrieving_Playlist_Contents – Julien 2012-03-02 10:49:23

0

只是想告诉时间应该提供为float,而不是int。 更换:

NSNumber * time =[NSNumber numberWithInt:10]; 

有:

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

将可能解决一些东西。

类似的答案:https://stackoverflow.com/a/17870972