1
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.

Shakiba Moshiri
  • 21,040
  • 2
  • 34
  • 44
Jaspreet Singh
  • 1,180
  • 2
  • 12
  • 30

4 Answers4

5

Do this:

Firstly extract videoID from Video URL Link.

Now refer this link for getting thumbnail of video.

Community
  • 1
  • 1
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
5

each youtube link has 4 thumbnail

   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:

      HPwyVw_6vsQ

and generated thumbnail from this link is:

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

this is very easy to use

Jaspreet Singh
  • 1,180
  • 2
  • 12
  • 30
1

if someone wants HQ image use this link

https://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
Abdul Karim
  • 4,359
  • 1
  • 40
  • 55
0

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:

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.

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

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

Jeff Posnick
  • 53,580
  • 14
  • 141
  • 167