119/test.html

294 lines
8.6 KiB
HTML
Raw Permalink Normal View History

2010-04-18 15:32:15 +00:00
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="vidList.js"></script>
<script type="text/javascript">
2010-11-23 23:20:33 +00:00
var VID_PATH = "file:///media/SeaEXT/Television/9-11/";
2010-04-18 15:32:15 +00:00
var NETWORKS = ['abc', 'bbc', 'cbs', 'cnn', 'fox', 'nbc'];
var currentVideos = {};
var timeInterval = -1;
var ALL_VIDEOS = {};
for (var n = 0; n < NETWORKS.length; n++) {
var network = NETWORKS[n];
ALL_VIDEOS[network] = [];
}
for (var i=0; i < VID_LIST.length; i++) {
var filename = VID_LIST[i],
network = filename.substring(0,3),
date = filename.substring(9,11),
start_time = filename.substring(11,15),
end_time = filename.substring(16,20);
ALL_VIDEOS[network].push({
'network': network,
'filename': filename,
'path': (VID_PATH + filename).replace("fox", "fox5"),
'date': parseInt(date, 10),
2010-11-23 23:20:33 +00:00
'start_time': new Date(2001, 8, parseInt(date, 10), getTimeHour(parseInt(start_time, 10)), getTimeMinutes(parseInt(start_time, 10))),
'end_time': new Date(2001, 8, parseInt(date, 10), getTimeHour(parseInt(end_time, 10)), getTimeMinutes(parseInt(end_time, 10))),
2010-04-18 15:32:15 +00:00
'id': '#' + network
});
}
function getVideosAtTime(d, t, channels) {
if (typeof channels == 'undefined') {
channels = NETWORKS;
2010-11-23 23:20:33 +00:00
}
var time = new Date(2001, 8, parseInt(d, 10), getTimeHour(t), getTimeMinutes(t));
2010-04-18 15:32:15 +00:00
var ret = {};
for (var c = 0; c < channels.length; c++) {
var channel = channels[c];
2010-11-23 23:20:33 +00:00
var v = getVideoAtTime(d, time, channel);
2010-04-18 15:32:15 +00:00
if (v) {
ret[channel] = v;
}
}
return ret;
}
function getVideoAtTime(d, t, network) {
for (var i=0; i < ALL_VIDEOS[network].length; i++) {
var thisVid = ALL_VIDEOS[network][i];
if (thisVid.date == d) {
if (thisVid.start_time < t && thisVid.end_time > t) {
return thisVid;
}
}
}
return false;
}
//accepts an integer like 1450, 45, 930, etc. Returns the correct hour of the time (NOTE: it will return 12 if the time is 45).
function getTimeHour(time) {
var timeString = time + '';
if (timeString.length == 4) {
return parseInt(timeString.substring(0,2));
}
if (timeString.length == 2) { // since we're converting from an int, this would be a time like 0045, which for the sake of math, is 1245 ..
return 12;
} else {
return parseInt(timeString.charAt(0));
}
}
function getSecs(time, start_time) {
var timeHr = getTimeHour(time);
var startHr = getTimeHour(start_time);
if (timeHr > startHr) {
time = time - 40;
}
return (time - start_time) * 60;
}
function getTimeMinutes(time) {
timeString = time + '';
var minutes = timeString.substring(timeString.length - 2, timeString.length);
return parseInt(minutes);
}
function getTime(startTime, currentTime, date) {
2010-11-23 23:20:33 +00:00
var currTime = startTime.getTime() + (currentTime * 1000);
return new Date(currTime);
2010-04-18 15:32:15 +00:00
}
$(function() {
$('#search').click(function() {
var date = parseInt($('#date').val());
var time = parseInt($('#time').val(), 10);
2010-11-23 23:20:33 +00:00
var timeObj = new Date(2001, 8, date, getTimeHour(time), getTimeMinutes(time));
2010-04-18 15:32:15 +00:00
console.log(time);
var videos = getVideosAtTime(date, time);
currentVideos = videos;
console.log(videos);
for (var v in videos) {
if (videos.hasOwnProperty(v)) {
var video = videos[v];
var id = '#' + video.network;
var jq = $(id);
2010-11-23 23:20:33 +00:00
var secondsToSeek = Math.floor((timeObj.getTime() - video.start_time.getTime()) / 1000);
2010-04-18 15:32:15 +00:00
var currPath = jq.attr("src");
if (currPath != video.path) {
jq.attr("src", video.path);
jq.get(0).load();
(function(vid, seconds) {
$('#' + video.network).one("loadedmetadata", function() {
console.log(vid.network, seconds);
this.currentTime = seconds;
this.play();
});
})(video, secondsToSeek);
} else {
jq.get(0).currentTime = secondsToSeek;
}
}
}
});
$('video').click(function(e) {
var that = this;
e.stopPropagation();
clearInterval(timeInterval);
$('.menu').remove();
var videoObj = currentVideos[$(that).attr('id')];
var start_time = videoObj.start_time;
var currentTime = getTime(start_time, $(this).get(0).currentTime, videoObj.date);
var html = tmpl("videoMenu", {
'network': videoObj.network,
'time': currentTime
});
var top = $(this).position().top;
var left = $(this).position().left;
$('body').append(html);
$('.menu').css({'top': top, 'left': left});
timeInterval = setInterval(function() {
var currentTime = getTime(start_time, $(that).get(0).currentTime, videoObj.date);
$('.menuCurrentTime').text(currentTime);
}, 800);
});
$('body').click(function() {
clearInterval(timeInterval);
$('.menu').remove();
});
2010-11-23 23:20:33 +00:00
$('#playAll').click(function() {
$('video').each(function() {
this.play();
});
});
$('#pauseAll').click(function() {
$('video').each(function() {
this.pause();
});
});
2010-04-18 15:32:15 +00:00
});
var menuActions = {
'muteThis': function(v) {
$(v.id).get(0).muted = !$(v.id).get(0).muted;
},
'muteOthers': function(v) {
for (var c in currentVideos) {
if (currentVideos.hasOwnProperty(c)) {
var t = currentVideos[c];
if (v.id != t.id) {
$(t.id).get(0).muted = true;
} else {
$(t.id).get(0).muted = false;
}
}
}
},
'pauseThis': function(v) {
$(v.id).get(0).pause();
},
'pauseOthers': function(v) {
for (var c in currentVideos) {
if (currentVideos.hasOwnProperty(c)) {
var t = currentVideos[c];
if (v.id != t.id) {
$(t.id).get(0).pause();
} else {
$(t.id).get(0).play();
}
}
}
}
}
$('.menuControls a').live("click", function(e) {
var videoObj = currentVideos[$(this).parents('.menu').attr('data-network')];
menuActions[$(this).attr('data-action')](videoObj);
});
/*
John Resig's micro-templating: http://ejohn.org/blog/javascript-micro-templating/
*/
(function(){
var cache = {};
window.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
tmpl(document.getElementById(str).innerHTML) :
// Generate a reusable function that will serve as a template
// generator (and which will be cached).
new Function("obj",
"var p=[],print=function(){p.push.apply(p,arguments);};" +
// Introduce the data as local variables using with(){}
"with(obj){p.push('" +
// Convert the template into pure JavaScript
str
.replace(/[\r\t\n]/g, " ")
.split("<%").join("\t")
.replace(/((^|%>)[^\t]*)'/g, "$1\r")
.replace(/\t=(.*?)%>/g, "',$1,'")
.split("\t").join("');")
.split("%>").join("p.push('")
.split("\r").join("\\'")
+ "');}return p.join('');");
// Provide some basic currying to the user
return data ? fn( data ) : fn;
};
})();
</script>
<style type="text/css">
.menu {
position: absolute;
background: #ccc;
}
</style>
</head>
<body>
<script type="text/html" id="videoMenu">
<div class="menu" data-network="<%= network %>">
<div class="menuMetadata">
Network: <%= network %> Time: <span class="menuCurrentTime"><%= time %></span>
</div>
<div class="menuControls">
<a class="muteThis" data-action="muteThis">Mute This</a>
<a class="muteOthers" data-action="muteOthers">Mute Others</a>
<a class="pauseThis" data-action="pauseThis">Pause This</a>
<a class="pauseOthers" data-action="pauseOthers">Pause Others</a>
</div>
</div>
</script>
<div id="wrapper">
<div id="header">
Date: <select id="date">
<option value="11">11th September</option>
<option value="12">12th September</option>
<option value="13">13th September</option>
</select>
Time: <input id="time" />
<button id="search">Get Videos</button>
2010-11-23 23:20:33 +00:00
<button id="playAll">Play All</button>
<button id="pauseAll">Pause All</button>
2010-04-18 15:32:15 +00:00
</div>
<div id="videos">
<div id="line1">
<video id="abc" controls></video>
<video id="bbc" controls></video>
<video id="cbs" controls></video>
</div>
<div id="line2">
<video id="cnn" controls></video>
<video id="fox" controls></video>
<video id="nbc" controls></video>
</div>
</div>
</div>
</body>
</html>