如何从Youtube网址获取缩略图?

时间:2012-10-04 13:03:28

标签: iphone ios xcode youtube youtube-api

NSURL *youTubeURL = [NSURL URLWithString:@"http://www.youtube.com/watch?v=HPwyVw_6vsQ&feature=youtu.be"]; // URL is a string which needs to be placed in @"" and close method call with ].
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:youTubeURL];
imageSel = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];

我正在使用此代码从视频获取缩略图,并在此返回null值 imagesel.can任何人帮我解决这个问题我正在使用YouTube网址。当我使用此代码作为主要包中的视频时,它工作正常。

4 个答案:

答案 0 :(得分:4)

这样做:

首先从视频网址链接中提取videoID。

现在请参阅this链接获取视频缩略图。

答案 1 :(得分:4)

每个YouTube链接都有4个缩略图

   http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
   http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
   http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
    http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg

此代码非常适合

例如,

 我有这个链接:

       http://www.youtube.com/watch?v=HPwyVw_6vsQ&feature=youtu.be

和youtube视频ID为:

      HPwyVw_6vsQ

并从此链接生成缩略图:

        http://img.youtube.com/vi/HPwyVw_6vsQ/1.jpg

这很容易使用

答案 2 :(得分:0)

如果您有YouTube观看页面网址,并且想要获取缩略图网址,那么&#34;更正&#34;这样做的方法是使用oEmbed:

http://apiblog.youtube.com/2009/10/oembed-support.html

这样您就不必尝试从网址中解析视频ID。

但是......你真正应该做的是使用iframe嵌入来显示网页中的视频(或UIWebView)。 YouTube API服务条款涵盖了支持访问YouTube内容的方式:

https://developers.google.com/youtube/terms

答案 3 :(得分:0)

如果有人想要总部图片,请使用此链接

https://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
相关问题