Reputation: 261
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.
Upvotes: 17
Views: 20044
Reputation: 763
just do that
String thumbnailul = "https://img.youtube.com/vi/" +videoid] + "/hqdefault.jpg";
Glide.with(context).load(thumbnailul).into(holder.iv_thumbnail);
Upvotes: 2
Reputation: 2487
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"
}
}
]
}
Upvotes: 3
Reputation: 9117
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
Upvotes: 39