<!DOCTYPE html>
<html>
<title>Clicking on YouTube Embedded Iframe - RJM Programming - June, 2016 - via Google YouTube API https://developers.google.com/youtube/iframe_api_reference</title>
<script type='text/javascript'>
var dostumps=true;
var vwidth=640;
var vheight=390;
var hone=1;
var vidarr;
var one=0;
var cntpause=0;
var onepause=0;
var tobechecked=null;
var thistext='';
var nexttext='2';
var nextvid='';
var nexturl='';
var of=' 1 of 1 ';
var cnt=0;
var toggle=1;
var secscnt=0;
var suffix="#t=00m00s";
var presuffix="";
var wo=null;
var yturl='';
var playtime=4000;
var delay=1300;
var vlen=0;
var eventtarget=null;
var duration=-1;
var previd="7o9wvYXR3n0";
var vid="7o9wvYXR3n0";
var hm=2;
var anymore='';
function etc_quality() {
return "<br>Quality <select id=iqty onchange=' player.setPlaybackQuality(this.value); '><option value='highres'>highres</option><option value='hd1080'>hd1080</option><option value='hd720'>hd720</option><option value='large'>large</option><option value='medium' selected>medium</option><option value='small'>small</option><option value='unknown'>unknown</option></select>";
}
function etc_playbackrate() {
return "<br>Playback Rate <select id=ipbr onchange=' player.setPlaybackRate(this.value); '><option value='0.25'>x 0.25</option><option value='0.5'>x 0.5</option><option value='1.5'>x 1.5</option><option value='1' selected>x 1</option><option value='2'>x 2</option></select>" + etc_quality();
}
function etc_volume() {
return "<br>Volume <input id=ivol onchange=' player.setVolume(this.value); ' type=number min=0 max=100 step=1 value=0></input>" + etc_playbackrate();
}
function postprompt(inp) {
if (inp == null) return "";
var oup=inp;
if (oup.indexOf(';') != -1) {
var ous=inp.split(';');
oup=ous[eval(-1 + ous.length)];
if (ous[0].indexOf(',') != -1) {
var ouss=ous[0].split(',');
vwidth=eval(ouss[0].replace('[','').replace(']',''));
vheight=eval(ouss[1].replace('[','').replace(']',''));
if (vwidth != 640 || vheight != 390) hone=0;
} else {
vwidth=eval(ous[0].replace('[','').replace(']',''));
if (ous.length >= 3) vheight=eval(ous[1].replace('[','').replace(']',''));
if (vwidth != 640 || vheight != 390) hone=0;
}
}
return oup;
}
function offerform() {
offerdform(hm);
}
function offerdform(howmany) {
var iid="id=i2 onblur=\"document.getElementById('vid').value=this.value;\"";
var odivc="<form id='oform' target='_self' action='./stop_start_youtube.htm' method='GET'><input type='hidden' value='2' name='this'></input><input type='hidden' value='-1' name='playtime'></input><input type='hidden' value='" + vidarr[0] + "' id='vid' name='vid'></input><input id='bsubmit' type='submit' value='Play' style='display:none;'></input><br>Current Video Playing 1 of " + howmany + " <input type='text' readonly value='" + vid + "' name='next'></input> ... and then ...";
for (var ij=2; ij<=howmany; ij++) {
odivc+="<br>Video to Play Later " + ij + " of " + howmany + " <input " + iid + " type='text' value='" + vidarr[eval(-1 + ij)] + "' name='next" + ij + "'></input>";
iid='';
}
odivc+="</form>";
document.getElementById('dform').innerHTML = odivc;
tobechecked=document.getElementById('i2');
}
function updatesc() {
cnt+=one;
cntpause+=onepause;
if (toggle == 0) secscnt+=one;
var ours="00" + eval(secscnt % 60);
var ourm="00" + eval((secscnt - ours) / 60);
suffix="#t=" + ourm.substring(eval(ourm.length - 2)) + "m" + ours.substring(eval(ours.length - 2)) + "s";
if (presuffix != "") presuffix=suffix;
if (eval(eval(cnt) - eval(cntpause)) >= duration && eval(duration) > 0) { // && eval(playtime) < 0) {
if (tobechecked != null) {
if (tobechecked.value != '') {
document.getElementById('oform').submit();
}
} else if (nexturl != '') {
location.href=nexturl;
} else {
secscnt=cnt;
stopVideo();
}
}
}
function followup() {
var lb='', ilb=2;
thistext=location.search.split('this=')[1] ? location.search.split('this=')[1].split('&')[0] : '';
if (thistext != '') {
of = ' ' + thistext + ' of ';
nexttext=eval(1 + eval(thistext));
} else if (document.URL.indexOf('next2=') != -1) {
of = ' 1 of ';
}
nextvid=location.search.split('next' + nexttext + '=')[1] ? location.search.split('next' + nexttext + '=')[1].split('&')[0] : '';
if (nextvid != '') {
nexturl=document.URL.replace('this=' + thistext + '&', 'this=' + nexttext + '&').replace('vid=' + vid, 'vid=' + nextvid);
}
//alert(nexttext + '=nexttext nextvid=' + nextvid + ' nexturl=' + nexturl);
if (document.URL.indexOf('next2=') != -1) {
while (document.URL.indexOf('next' + ilb + '=') != -1) {
ilb++;
}
lb=eval(ilb - 1);
of+=lb + ' ';
}
}
</script>
</head>
<body onload=' followup(); setInterval(updatesc,1000);'>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
vwidth=location.search.split('width=')[1] ? eval(location.search.split('width=')[1].split('&')[0]) : vwidth;
vheight=location.search.split('height=')[1] ? eval(location.search.split('height=')[1].split('&')[0]) : vheight;
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
if (document.URL.indexOf('vid=') != -1) {
vid=location.search.split('vid=')[1] ? location.search.split('vid=')[1].split('&')[0] : postprompt(prompt('Please enter YouTube video id (or a comma separated list of these), optionally prefixed by [640;][390;] which is [width;][height;]', previd));
vidarr=vid.split(',');
var splaytime="";
if (vid.indexOf(',') != -1) {
vid=vidarr[0];
splaytime=eval(-vidarr.length);
} else {
splaytime=location.search.split('playtime=')[1] ? location.search.split('playtime=')[1].split('&')[0] : prompt('Please enter YouTube video ' + vid + ' playtime snippets in seconds (-1 to play whole video in one session, -2 (or -n) to play whole video and perhaps more (n in total) to follow in one session)', playtime / 1000);
}
if (document.URL.indexOf('playtime=') != -1) {
playtime=eval(eval("" + splaytime) * 1);
} else if (("" + splaytime) != "-1" && ("" + splaytime).indexOf("-") == 0) {
playtime=eval(-1 * 1000);
hm=eval(("" + splaytime).replace('-',''))
of=' 1 of up to ' + hm + ' ';
setTimeout(offerform,2000);
} else {
playtime=eval(eval("" + splaytime) * 1000);
}
} else {
vid=location.search.split('vid=')[1] ? location.search.split('vid=')[1].split('&')[0] : postprompt(prompt('Please enter YouTube video id (or a comma separated list of these), optionally prefixed by [640;][390;] which is [width;][height;]', previd));
vidarr=vid.split(',');
var ssplaytime="";
if (vid.indexOf(',') != -1) {
vid=vidarr[0];
ssplaytime=eval(-vidarr.length);
} else {
ssplaytime=location.search.split('playtime=')[1] ? location.search.split('playtime=')[1].split('&')[0] : prompt('Please enter YouTube video ' + vid + ' playtime snippets in seconds (-1 to play whole video in one session, -2 (or -n) to play whole video and perhaps more (n in total) to follow in one session)', playtime / 1000);
}
if (document.URL.indexOf('playtime=') != -1) {
playtime=eval(eval("" + ssplaytime) * 1);
} else if (("" + ssplaytime) != "-1" && ("" + ssplaytime).indexOf("-") == 0) {
playtime=eval(-1 * 1000);
hm=eval(("" + ssplaytime).replace('-',''))
if (hm > hone) {
anymore='&this=&width=' + vwidth + '&height=' + vheight + '&next=' + vid;
for (var iu=2; iu<=hm; iu++) {
anymore+='&next' + iu + '=' + vidarr[eval(-1 + iu)];
}
}
of=' 1 of up to ' + hm + ' ';
//alert(vid + " " + ssplaytime + " " + ("" + ssplaytime).indexOf("-") + " " + hm);
setTimeout(offerform,2000);
} else if (hone == 0) {
anymore='&this=&width=' + vwidth + '&height=' + vheight + '&next=' + vid;
playtime=eval(eval("" + ssplaytime) * 1000);
} else {
playtime=eval(eval("" + ssplaytime) * 1000);
}
if ((vid != previd && vid.indexOf(',') == -1) || vwidth != 640 || vheight != 390) location.href='./stop_start_youtube.htm?vid=' + vid + '&playtime=' + playtime + anymore;
}
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: vheight,
width: vwidth,
videoId: vid,
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
toggle=eval(1 - toggle);
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
one=0;
onepause=0;
if (event.data == YT.PlayerState.PLAYING) one=1;
if (event.data == YT.PlayerState.PAUSED) onepause=1;
if (event.data == YT.PlayerState.PLAYING && !done) {
duration=player.getDuration();
if (playtime < 0) playtime=duration * 1000;
document.title='Playing YouTube ' + vid + of + ' for ' + playtime / 1000 + ' seconds ... is ' + duration + ' seconds altogether.';
document.getElementById('ptitle').innerHTML='Playing YouTube ' + vid + of + ' for ' + playtime / 1000 + ' seconds ... is ' + duration + ' seconds altogether.' + etc_volume();
document.getElementById('ivol').value=player.getVolume();
document.getElementById('ipbr').value=player.getPlaybackRate();
document.getElementById('iqty').value=player.getPlaybackQuality();
setTimeout(stopVideo, playtime + delay);
done = true;
eventtarget=event.target;
}
}
function stopVideo() {
if (cntpause > 0) {
setTimeout(stopVideo, cntpause * 1000);
cntpause=0;
} else {
var dorest=true;
toggle=1;
secscnt=player.getCurrentTime();
duration=player.getDuration();
//alert('preone' + playtime);
if (playtime < 0) playtime=duration * 1000;
//alert('Preone' + dorest);
player.stopVideo();
//alert(secscnt);
if (secscnt >= duration) {
if (tobechecked != null) {
if (tobechecked.value != '') {
dorest=false;
document.getElementById('oform').submit();
//document.getElementById('bsubmit').click();
}
}
if (dorest) {
if (nexturl != "") {
location.href=nexturl;
} else if ('old' == 'new') {
alert("Stumps has been called. End of play.");
} else if (dostumps) {
dostumps=false;
var donext=prompt("Stumps has been called. End of play. Is there a YouTube video id to play next?", "");
if (donext == null) donext='';
if (donext != '') location.href='./stop_start_youtube.htm?vid=' + donext;
}
}
} else {
setTimeout(startVideo, playtime + delay);
}
}
}
function startVideo() {
var dorest=true;
//alert('PREone ' + secscnt + ' ' + duration + ':' + dorest);
if (secscnt >= duration) {
if (tobechecked != null) {
if (tobechecked.value != '') {
dorest=false;
document.getElementById('oform').submit();
//document.getElementById('bsubmit').click();
}
}
if (dorest) {
if (nexturl != "") {
location.href=nexturl;
} else if ('old' == 'new') {
alert("Stumps is called. End of play.");
} else if (dostumps) {
dostumps=false;
var donext=prompt("Stumps is called. End of play. Is there a YouTube video id to play next?", "");
if (donext == null) donext='';
if (donext != '') location.href='./stop_start_youtube.htm?vid=' + donext;
}
}
} else {
//alert('two');
document.title='Playing YouTube ' + vid + ' starting at ' + secscnt + ' seconds to ' + Math.min(duration, eval(secscnt + (playtime / 1000))) + ' seconds for up to ' + playtime / 1000 + ' seconds ... is ' + duration + ' seconds altogether.';
document.getElementById('ptitle').innerHTML='Playing YouTube ' + vid + ' starting at ' + secscnt + ' seconds to ' + Math.min(duration, eval(secscnt + (playtime / 1000))) + ' seconds for up to ' + playtime / 1000 + ' seconds ... is ' + duration + ' seconds altogether.' + etc_volume();
document.getElementById('ivol').value=player.getVolume();
document.getElementById('ipbr').value=player.getPlaybackRate();
document.getElementById('iqty').value=player.getPlaybackQuality();
eventtarget.cueVideoById(vid, secscnt, secscnt + playtime / 1000, "medium");
toggle=0;
player.playVideo();
setTimeout(stopVideo, playtime + delay);
}
}
</script>
<div id='ptitle'></div>
<div id='dform' style='background-color:yellow;'></div>
</body>
</html>