xcode 如何从 Youtube URL 获取缩略图?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12727907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:42:23  来源:igfitidea点击:

How can I get the Thumbnail from Youtube URL?

iphoneiosxcodeyoutubeyoutube-api

提问by Jaspreet Singh

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

I am using this code for getting thumbnail from the video and this return null value in the imagesel.can anybody help me to solve this problem I am using YouTube URL .when I am using this code for the video that is in the main bundle then it is working fine.

我正在使用此代码从视频中获取缩略图,并在 imagesel 中返​​回空值。有人可以帮我解决这个问题吗?我正在使用 YouTube URL。当我将此代码用于主包中的视频时它工作正常。

回答by Paresh Navadiya

Do this:

做这个:

Firstly extract videoID from Video URL Link.

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

Now refer thislink for getting thumbnail of video.

现在参考链接获取视频缩略图。

回答by Jaspreet Singh

each youtube link has 4 thumbnail

每个 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

this code is very good for

这段代码非常适合

for example i have this link:

例如我有这个链接:

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

and the youtube video id is:

和 youtube 视频 ID 是:

      HPwyVw_6vsQ

and generated thumbnail from this link is:

并从此链接生成的缩略图是:

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

this is very easy to use

这很容易使用

回答by Jeff Posnick

If you have a YouTube watch page URL, and you want to get the thumbnail URL, the "correct" way to do that is to use oEmbed:

如果您有 YouTube 观看页面 URL,并且想要获取缩略图 URL,那么“正确”的方法是使用 oEmbed:

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

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

That way you don't have to attempt to parse the video id out of the URL.

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

But... what you really should be doing is using a iframeembed to display videos in your web page (or UIWebView). The YouTube API Terms of Service covers the supported ways of accessing YouTube content:

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

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

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