Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get video thumbnail from YouTube URL and set it to image view in android

I want to create an application in which I want to play YouTube video. I want to get thumbnail from YouTube video URL which I have currently play in application and set it to image view. can any body help me with this.

like image 221
Muhammad zubair Avatar asked May 10 '17 13:05

Muhammad zubair


People also ask

How do I get a YouTube thumbnail link?

You can use the youtubethumbnail. download tool to download the thumbnail of any YouTube video here. The tool is really simple and allows you to see online the 4 thumbnails in the 4 different qualities, you can copy the link of the image to the clipboard or you can directly download the image.


2 Answers

Use this url.. just replace with your youtude video id

String url = "https://img.youtube.com/vi/"+{ID}+"/0.jpg";
Glide.with(this).load(url).into(imageView);

Option 1 – Get the custom thumbnail in 320 x 180 small image resolution

http://img.youtube.com/vi/{ID}/mqdefault.jpg

Option 2 – Get the custom thumbnail in 480 x 360 standard image resolution

http://img.youtube.com/vi/{ID}/0.jpg

Option 3 – Get the custom thumbnail in 720p or 1080p HD image resolution

http://img.youtube.com/vi/{ID}/maxresdefault.jpg



OR

just use YoutubeThumbnail API

like image 197
ZeroOne Avatar answered Sep 20 '22 05:09

ZeroOne


You can use YouTube API v3 to retrieve related video thumbnail info like title, image and length:

https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet&fields=items/snippet(title,thumbnails),items/contentDetails/duration&key={{ YOUR_API_KEY }}&id={{ YOUR_YOUTUBE_VIDEO_ID }}

Or this url if you only want to get only thumbnail image with medium size:

https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet&fields=items/snippet(title,thumbnails/medium/url),items/contentDetails/duration&key={{ YOUR_API_KEY }}&id={{ YOUR_YOUTUBE_VIDEO_ID }}

Your response may look like this:

{
 "items": [
  {
   "snippet": {
    "title": "F..k This S..t I'm Out",
    "thumbnails": {
     "medium": {
      "url": "https://i.ytimg.com/vi/5FjWe31S_0g/mqdefault.jpg"
     }
    }
   },
   "contentDetails": {
    "duration": "PT25S"
   }
  }
 ]
}
like image 30
Tam Huynh Avatar answered Sep 22 '22 05:09

Tam Huynh