Monday, June 6, 2011

Playing you tube videos with java script


First thing to play a you tube video, download the swfobject.js file.

<script type="text/javascript" src="swfobject.js"></script>

<div id="showvideo">
</div>

<script type="text/javascript">
    var vid="Vb7xpSeVe6c";
    swfobject.embedSWF("http://www.youtube.com/v/"+vid+"?enablejsapi=1&amp;version=3&amp;border=0", "showvideo", "450", "350", "8", null, null);
</script>


Here vid is the video id of the video, which you want to play with the help of java script. You can easily see this video id as a v parameter in any video link which you tube plays.