1
votes

I want something that convert youtube thumbnail(image format) in youtube video embed form

Like youtube thumbnail

http://img.youtube.com/vi/UJ1MOWg15Ec/default.jpg

and i want to convert it by javascript or jquery like this

<iframe width="560" height="315" src="https://www.youtube.com/embed/UJ1MOWg15Ec" frameborder="0" allowfullscreen></iframe>

can any one help me to find out solution, i tried lot of code but nothing working work for me and didn't find and Q and A in stackoverflow please help me solve this

1

1 Answers

0
votes

So you want to replace the thumbnail to an embed code. I guess the only thing you need is to grab the videoID from the thumbnail URL and place it inside the HTML that forms the embed code.

Something like this should work:

var match = 'http://img.youtube.com/vi/UJ1MOWg15Ec/default.jpg'.match('vi/([^\/]+)/');
var videoID = match[1];
var embed = '<iframe width="560" height="315" src="https://www.youtube.com/embed/' + videoID + '" frameborder="0" allowfullscreen></iframe>';

See Fiddle