Replace url with video
by Rajesh Sitaraman
HTML
<div id='player'></div>
JavaScript
var videoUrl = "https://www.youtube.com/watch?v=PFT3kXm7MGQ";
videoUrl = "https://vine.co/v/bjHh0zHdgZT";
var youEmbed = '<iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/$1" allowfullscreen frameborder="0" hd=1 showinfo=0 ></iframe>';
var vimeoEmbed = '<iframe src="//player.vimeo.com/video/$1" width="200" height="100" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
var vineEmbed = '<iframe src="//vine.co/$1/embed/simple" width="480" height="480" frameborder="0"></iframe>';
videoUrl = videoUrl.replace(/(?:http:\/\/)?(?:https:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/g, youEmbed).replace(/(?:http:\/\/)?(?:https:\/\/)(?:www\.)?(?:vimeo\.com)\/(.+)/g, vimeoEmbed).replace(/(?:http:\/\/)?(?:https:\/\/)?(?:www\.)?(?:vine\.co)\/?(.+)/g, vineEmbed);
console.log(videoUrl);
$('#player').html(videoUrl);