Nonstop vid. See newer: http://www.slideshare.net/phanhung20/playing-videos-continuously

331 views

Published on

This is simple html file with javascript. The target is to play many youtube videos continously one after another. Just find in youtube.com page the ID (11 character/number) of video, it's duration and title and put all them in our html file.

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
331
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Nonstop vid. See newer: http://www.slideshare.net/phanhung20/playing-videos-continuously

  1. 1. HOW TO PLAY YOUTUBE VIDEOS ONE AFTER ANOTHERWe can use function getDuration() in "swfobject.js" with data retrievingfrom the Google "gdata.feeds" webs. But the exactness in one or twoseconds seems to me is not necessary. So I take the easiest way, usingthe familiar function setTimeout("..",1000). Next is the code.<script>function play(i){c = 0;window.scrollTo(0,0);obj = document.getElementById("vidTitle");obj.innerHTML = <b>+tit[i]+</b>;obj = document.getElementById("player1");stID = "http://www.youtube.com/embed/" + vid[i] + "?autoplay=1";obj.setAttribute("src",stID);}var c = 0; var j = 0;function count(){last = vid.length - 1;c = c + 1;obj = document.getElementById("showSeconds");obj.value = c + " / dur:" + dur[j];if(c>dur[j]){if(j<=last){j=j+1; play(j)}if (j>last){j=1;play(j)}}mytimer = setTimeout("count()",1000);}function nextVideo(){last = vid.length -1;if(j<=last){j=j+1;play(j);}if (j>last){j=1;play(j);}}function endVid(){clearTimeout(mytimer);st = "http://www.youtube.com/embed/ntGJ2vkLbIo?autoplay=0";obj = document.getElementById("player1");obj.setAttribute("src",st);obj = document.getElementById("vidTitle");obj.innerHTML = ;c = 0; j = 0;}function sec(m,s){return m*60 + s;}function t(ti){tit.push(ti);}function v(vi){vid.push(vi);}function d(du){dur.push(du);}function quit(){if(mytimer){clearTimeout(mytimer);}
  2. 2. }//Creating three arraystit = []; vid = []; dur = [];k=0;tit[k]="" ;vid[k]="" ;dur[k]=0;t("Richard Abel - Spanish Eyes") ;v("ntGJ2vkLbIo");d(183);t("CUANDO SALI DE CUBA- SUSANA PEÑA");v("9CLAAJYRo-I");d(95);t("FRANCK POURCELL - BESAME MUCHO");v("RK208ZT82Is");d(sec(3,12));// In the youtube.com page "franck pourcel besame mucho"// you see: duration of the video is 3:12. Function sec(..) willreturn 192 seconds.</script></head><body onload="quit()"><div align="center"><iframe id="player1" width="835" height="480"src="http://www.youtube.com/embed/ntGJ2vkLbIo?autoplay=0"frameborder="0" allowfullscreen ></iframe><br>You are watching:<br><span id="vidTitle"></span><br><input type="button" value="Play All" onclick="count()">&nbsp;<input type="button" value="End" onclick="endVid()">&nbsp;<input type="text" id="showSeconds" value="0/dur" size=28 style="text-align:center">&nbsp;<input type="button" value="Next" onclick="nextVideo()"></div>

×