-changes to now playing bar

This commit is contained in:
mkonecny 2011-01-24 19:19:51 -05:00
parent 5173674714
commit c8b7cffdc6
9 changed files with 200 additions and 110 deletions

View file

@ -1,71 +1,16 @@
var estimatedSchedulePosixTime = -1;
var schedulePosixTime;
var previousSongs;
var currentSong;
var nextSongs;
var currentRemoteTimeOffset;
var previousSongs = new Array();
var currentSong = new Array();
var nextSongs = new Array();
var currentElem;
function init(elemID) {
var currentElem = $("#" + elemID).attr("style", "z-index: 1; width: 100%; left: 0px; right: 0px; bottom: 0px; color: black; min-height: 100px; background-color: #FEF1B5;");
$('#progressbar').progressBar(0, {showText : false});
var updateInterval = 5000;
getScheduleFromServer();
updateProgressBarValue();
}
function convertDateToPosixTime(s){
var year = s.substring(0, 4);
var month = s.substring(5, 7);
var day = s.substring(8, 10);
var hour = s.substring(11, 13);
var minute = s.substring(14, 16);
var sec = s.substring(17, 19);
var msec = 0;
if (s.length >= 20){
msec = s.substring(20);
}
return Date.UTC(year, month, day, hour, minute, sec, msec);
}
function secondsTimer(){
estimatedSchedulePosixTime += 1000;
updateProgressBarValue();
}
/* Called every 1 second. */
function updateProgressBarValue(){
if (estimatedSchedulePosixTime != -1){
if (currentSong.length > 0){
var percentDone = (estimatedSchedulePosixTime - currentSong[0].songStartPosixTime)/currentSong[0].songLengthMs*100;
if (percentDone <= 100){
$('#progressbar').progressBar(percentDone);
} else {
if (nextSongs.length > 0){
currentSong[0] = nextSongs.shift();
} else {
currentSong = new Array();
}
$('#progressbar').progressBar(0);
//at the end of each song we are updating the
//server time we have been estimating client-side
//with the real server time.
estimatedSchedulePosixTime = schedulePosixTime;
}
} else
$('#progressbar').progressBar(0);
updatePlaylist();
}
setTimeout(secondsTimer, 1000);
}
function getTrackInfo(song){
return song.track_title + " - " + song.artist_name + " - " + song.album_title;
}
function convertToHHMMSS(timeInMS){
var time = parseInt(timeInMS);
@ -91,19 +36,89 @@ function convertToHHMMSS(timeInMS){
return "" + hours + ":" + minutes + ":" + seconds;
}
function convertDateToPosixTime(s){
var year = s.substring(0, 4);
var month = s.substring(5, 7);
var day = s.substring(8, 10);
var hour = s.substring(11, 13);
var minute = s.substring(14, 16);
var sec = s.substring(17, 19);
var msec = 0;
if (s.length >= 20){
msec = s.substring(20);
}
return Date.UTC(year, month, day, hour, minute, sec, msec);
}
function getTrackInfo(song){
var str = "";
if (song.track_title != null)
str += song.track_title;
if (song.artist_name != null)
str += " - " + song.artist_name;
if (song.album_title != null)
str += " - " + song.album_title;
return str;
}
function secondsTimer(){
var date = new Date();
estimatedSchedulePosixTime = date.getTime() - currentRemoteTimeOffset;
updateProgressBarValue();
}
/* Called every 1 second. */
function updateProgressBarValue(){
if (estimatedSchedulePosixTime != -1){
if (currentSong.length > 0){
var percentDone = (estimatedSchedulePosixTime - currentSong[0].songStartPosixTime)/currentSong[0].songLengthMs*100;
if (percentDone <= 100){
$('#progressbar').progressBar(percentDone);
} else {
if (nextSongs.length > 0){
currentSong[0] = nextSongs.shift();
} else {
currentSong = new Array();
}
$('#progressbar').progressBar(0);
}
} else {
$('#progressbar').progressBar(0);
//calculate how much time left to next song if there is any
if (nextSongs.length > 0){
if (nextSongs[0].songStartPosixTime - estimatedSchedulePosixTime < updateInterval){
setTimeout(temp, nextSongs[0].songStartPosixTime - estimatedSchedulePosixTime);
}
}
}
updatePlaylist();
}
setTimeout(secondsTimer, 200);
}
function temp(){
currentSong[0] = nextSongs[0];
updatePlaylist();
}
function updatePlaylist(){
/* Column 0 update */
$('#listen');
$('#volume');
/* Column 1 update */
$('#show').empty();
$('#playlist').empty();
$('#host').empty();
for (var i=0; i<currentSong.length; i++){
$('#show').append(currentSong[i].show);
//alert (currentSong[i].playlistname);
//$('#show').append(currentSong[i].show);
$('#playlist').append(currentSong[i].playlistname);
$('#host').append(currentSong[i].creator);
//$('#host').append(currentSong[i].creator);
}
/* Column 2 update */
@ -141,18 +156,15 @@ function calcAdditionalData(currentItem){
}
}
function prepareNextPlayingItem(obj){
if (obj.next.length > 0){
var nextItem = obj.next[0];
}
}
function parseItems(obj){
schedulePosixTime = convertDateToPosixTime(obj.schedulerTime);
if (estimatedSchedulePosixTime == -1)
if (estimatedSchedulePosixTime == -1){
var date = new Date();
currentRemoteTimeOffset = date.getTime() - schedulePosixTime;
estimatedSchedulePosixTime = schedulePosixTime;
}
previousSongs = obj.previous;
currentSong = obj.current;
nextSongs = obj.next;
@ -166,5 +178,15 @@ function getScheduleFromServer(){
$.ajax({ url: "/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){
parseItems(data.entries);
}});
setTimeout(getScheduleFromServer, 5000);
setTimeout(getScheduleFromServer, updateInterval);
}
function init(elemID) {
var currentElem = $("#" + elemID).attr("style", "z-index: 1; width: 100%; left: 0px; right: 0px; bottom: 0px; color: black; min-height: 100px; background-color: #FEF1B5;");
$('#progressbar').progressBar(0, {showText : false});
getScheduleFromServer();
updateProgressBarValue();
}