Powered By Blogger

Monday, February 22, 2016

How to get the YouTube thumbnail preview image from a video

You need the id of the video which is in the url after v=
https://www.youtube.com/watch?v=9bZkp7q19f0
When you have the video id, you can use it in this url to get the image. 
URL
https://i.ytimg.com/vi/{0}/maxresdefault.jpg
@{
 string gangnamStyleYouTubeId = "9bZkp7q19f0";
 const string YOUTUBE_PREVIEW_IMAGE_URL = "https://i.ytimg.com/vi/{0}/maxresdefault.jpg";
}

<img src="@String.Format(YOUTUBE_PREVIEW_IMAGE_URL, gangnamStyleYouTubeId)" />
//The output will be

<img src="https://i.ytimg.com/vi/9bZkp7q19f0/maxresdefault.jpg">
I trust this has been pretty straight forward for you to follow. If you have any questions, feel free to write them in the comments. Don't forget to share this post with your friends and colleagues.

No comments:

Post a Comment