Prashant Chaudhari
Prashant Chaudhari

Reputation: 1339

Thumbnail Image From Youtube

I want to create thumbnail image from youtube url. I am trying thumbnailImageAtTime method but cant able to create thumbnail image. Please Help me.

Here is my code:

 MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=02Bzjj1eeeo"]];

UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
[imgview setImage:thumbnail];
[player stop];

Upvotes: 4

Views: 1314

Answers (2)

user2975466
user2975466

Reputation: 1

You can retrieve it easily by using below youtube api url “http://img.youtube.com/vi/” + youtubeVideoID + “/default.jpg”

for more details, check this link blogfornet-youtube thumbnail.

Upvotes: -1

Saurabh Singh
Saurabh Singh

Reputation: 247

the best way is to get the frame of the video and use that image frame with that youtube url:

NSString *urlStringImage=[NSString stringWithFormat:@"http://img.youtube.com/vi/%@/1.jpg",idOfYoutubeVideo];
NSData thumbnailImageData=[NSData dataWithContentsOfURL:[NSURL URLWithString:urlStringImage]];

Eg: http://www.youtube.com/watch?v=K8cJKirMo-A

video id = K8cJKirMo-A

urlStringImage = http://img.youtube.com/vi/K8cJKirMo-A/default.jpg

use default.png instead of 1.jpg

Upvotes: 3

Related Questions