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.
Nonstop vid. See newer: http://www.slideshare.net/phanhung20/playing-videos-continuously
1. HOW TO PLAY YOUTUBE VIDEOS ONE AFTER ANOTHER
We can use function getDuration() in "swfobject.js" with data retrieving
from the Google "gdata.feeds" webs. But the exactness in one or two
seconds seems to me is not necessary. So I take the easiest way, using
the 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. }
//Creating three arrays
tit = []; 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(..) will
return 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()">
<input type="button" value="End" onclick="endVid()">
<input type="text" id="showSeconds" value="0/dur" size=28 style="text-
align:center">
<input type="button" value="Next" onclick="nextVideo()">
</div>