【问题标题】:iphone dev getting video thumbnail (frame) from MPMoviePlayerControlleriphone dev 从 MPMoviePlayerController 获取视频缩略图(帧)
【发布时间】:2012-03-01 09:07:47
【问题描述】:

我试图从视频 url 获取视频帧或缩略图但没有成功的每个人,这是我的代码

- (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 也没有触发,请。告诉我我做错了什么以及如何纠正它,提前谢谢,问候萨德

【问题讨论】:

    标签: iphone


    【解决方案1】:

    无法使用 MPMoviePlayerController 从 YouTube 读取视频尝试使用其他视频(来自 m3u8 播放列表或 MP4 文件)。

    【讨论】:

    • Thanx Julien,但我有你管视频链接,我的要求是我必须在表格视图单元格中显示视频标题及其缩略图,当用户点击它时,我将播放视频,所以请。告诉我是否有任何解决方法
    • 查看 YouTube 网络服务,您可能会找到解决方案。 developers.google.com/youtube/2.0/…
    【解决方案2】:

    只是想告诉时间应该提供为浮点数,而不是整数。 替换:

    NSNumber * time =[NSNumber numberWithInt:10];
    

    与:

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

    也许会解决一些问题。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-25
      • 2012-04-14
      • 2013-08-31
      • 2017-10-21
      • 2011-05-25
      • 2013-12-22
      • 1970-01-01
      相关资源
      最近更新 更多