Commit e724d91c authored by Michael Murtaugh's avatar Michael Murtaugh
Browse files

(a yet another) new player

parent 1d9a2e3a
<!DOCTYPE>
<html>
<head>
<meta charset="utf-8" />
<title>player</title>
<style>
body {
margin: 0;
}
iframe {
width: 100%;
height: 100%;
border: none;
background: pink;
}
</style>
</head>
<body>
<iframe id="iframe"></iframe>
<script>
/* LIBRARY ROUTINES */
var parseQueryString = function( queryString ) {
var params = {}, queries, temp, i, l;
// Split into key/value pairs
queries = queryString.split("&");
// Convert the array of strings into an object
for ( i = 0, l = queries.length; i < l; i++ ) {
temp = queries[i].split('=');
params[temp[0]] = decodeURIComponent(temp[1]);
}
return params;
};
function aa_secondsToTimecode (ss, style) {
style = timecode_styles[style || 'html5'];
var h = Math.floor(ss/3600),
m,
s,
fract,
ret;
ss -= (h * 3600);
m = Math.floor(ss / 60);
ss -= (m * 60);
s = Math.floor(ss);
fract = style.delimiter + (""+(ss - s)).substr(2, 3);
while (fract.length < 4) { fract += "0"; } // PAD TO ALWAYS BE THREE DIGITS LONG (eg .040)
ret = (h || style.requireHours ? ((((h<10)?"0":"")+h)+":") : '')
ret += (((m<10)?"0":"")+m)+":"+(((s<10)?"0":"")+s)+fract;
return ret;
}
timecode_styles = {
'srt': {
requireHours: true,
delimiter: ','
},
'html5': {
requireHours: false,
delimiter: '.'
}
}
function aa_timecodeToSeconds (tc) {
var tcpat = /^(?:(\d\d):)?(\d\d):(\d\d(?:[\.,](?:\d{1,3}))?)$/,
groups = tcpat.exec(tc);
if (groups != null) {
var h = groups[1] !== undefined ? parseInt(groups[1]) : 0,
m = parseInt(groups[2]),
s = parseFloat(groups[3].replace(/,/, "."));
return (h * 3600) + (m * 60) + s;
}
}
/* */
// window.addEventListener("message", function (e) {
// // console.log("message", e);
// if (e.data.msg == "fragmentclick" && e.data.hash.t[0].startNormalized) {
// audio.currentTime = e.data.hash.t[0].startNormalized;
// } else if (e.data.msg == "cc_toggle") {
// if (audio.paused) {
// audio.play();
// } else {
// audio.pause();
// }
// } else if (e.data.msg == "cc_left") {
// audio.currentTime -= 5;
// } else if (e.data.msg == "cc_right") {
// audio.currentTime += 5;
// }
// }, false);
var iframe = document.getElementById("iframe"),
current_src,
current_hash,
media;
function on_timeupdate () {
localStorage.setItem("ccfragment", "t="+aa_secondsToTimecode(media.currentTime))
}
iframe.addEventListener("load", function () {
console.log("iframe.load");
media = iframe.contentDocument.querySelector("audio,video");
if (media) {
console.log("listening to timeupdate events")
media.addEventListener("timeupdate", on_timeupdate);
}
})
function update_location () {
var vars = parseQueryString(window.location.hash.substring(1));
// console.log("video.html, update_location", vars);
iframe.src = vars.href;
current_src = vars.href;
localStorage.setItem("cchref", vars.href);
localStorage.removeItem("ccfragment");
// audio.play();
}
console.log("listening to storage");
window.addEventListener("storage", function (e) {
console.log("storage", e);
if (e.key == "cccontrol") {
// console.log("e.value", e.newValue);
var d = JSON.parse(e.newValue);
if (d.cmd == "toggle") {
if (media && media.paused) {
media.play();
} else {
media.pause();
}
} else if (d.cmd == "left") {
if (media) {
media.currentTime = media.currentTime - 5;
}
} else if (d.cmd == "right") {
if (media) {
media.currentTime = media.currentTime + 5;
}
}
}
}, false);
window.addEventListener("hashchange", function (e) {
update_location();
// var h = window.location.hash;
// // console.log("hashchange", h);
// if (h !== current_hash) {
// // act on it
// current_hash = h;
// var vars = parseQueryString(h.substring(1));
// if (vars.href !== current_src) {
// audio.src = vars.href;
// current_src = vars.href;
// audio.play();
// }
// if (vars.start) {
// audio.currentTime = aa_timecodeToSeconds(vars.start);
// audio.play();
// }
// }
});
// audio.addEventListener("timeupdate", function () {
// // console.log("timeupdate", this.currentTime);
// var start = audio.currentTime,
// start_tc = aa_secondsToTimecode(start);
// // current_hash = "#href="+current_src+"&t=" + aa_secondsToTimecode(audio.currentTime);
// // window.location.hash = current_hash;
// window.postMessage({
// msg: "fragmentchange",
// href: current_src,
// value: current_src+"#t="+start_tc,
// hash: {
// t: [{
// start: start_tc,
// startNormalized: start,
// unit: "npt",
// value: start_tc,
// end: "",
// endNormalized: ""
// }]
// }
// }, "*");
// });
update_location();
</script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment