This post will help you if you want to get the preview image for a YouTube video. You may want to you this if you want to trigger the video to launch in a pop up window, or you want to link to the video.
I'm not sure how far back it goes, but it works for PSY's Gangnam Style which is from July 2012 and Justin Beiber's Baby which is from February 2010.
You need the id of the video which is in the url after v=
https://www.youtube.com/watch?v=cIboJm2WzKY
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 youTubeId = "cIboJm2WzKY";
const string YOUTUBE_PREVIEW_IMAGE_URL = "https://i.ytimg.com/vi/{0}/maxresdefault.jpg";
}
<img src="@String.Format(YOUTUBE_PREVIEW_IMAGE_URL, youTubeId)" />
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.
Umbraco MVP and .NET Web Developer from Derby (UK) who specialises in building Content Management System (CMS) websites using MVC with Umbraco as a framework. Paul is passionate about web development and programming as a whole. Apart from when he's with his wife and son, if he's not writing code, he's thinking about it or listening to a podcast about it.
This post shows you how you can change the colour and animate tree icons in Umbraco based on a prope…
Read PostIn this post, Mike Masey shows you how you can flip an image using CSS.
Read PostThis post will show you how to build a carousel in umbraco using Nested Content and Bootstrap
Read PostThis post shows you how to create an extension method for returning formatted HTML from a string inp…
Read Post