-fixed bug CC-1837

-show progress-bar will now update even when an audio item is not playing
This commit is contained in:
mkonecny 2011-02-01 20:28:38 -05:00
parent be79b21c37
commit 71023a52b3
5 changed files with 201 additions and 170 deletions

View File

@ -4,11 +4,7 @@ class Application_Model_Nowplaying
{ {
public static function GetDataGridData(){ public static function GetDataGridData(){
$timeNow = Schedule::GetSchedulerTime();
$previous = Schedule::GetPreviousItems($timeNow, 1);
$current = Schedule::GetCurrentlyPlaying($timeNow);
$next = Schedule::GetNextItems($timeNow, 10);
$columnHeaders = array(array("sTitle"=>"type", "bVisible"=>false), $columnHeaders = array(array("sTitle"=>"type", "bVisible"=>false),
array("sTitle"=>"Date"), array("sTitle"=>"Date"),
array("sTitle"=>"Start"), array("sTitle"=>"Start"),
@ -21,30 +17,44 @@ class Application_Model_Nowplaying
array("sTitle"=>"Playlist"), array("sTitle"=>"Playlist"),
array("sTitle"=>"bgcolor", "bVisible"=>false), array("sTitle"=>"bgcolor", "bVisible"=>false),
array("sTitle"=>"group_id", "bVisible"=>false)); array("sTitle"=>"group_id", "bVisible"=>false));
$rows = array();
$current_group_id = -1; $timeNow = Schedule::GetSchedulerTime();
if (count($current) != 0){ $currentShow = Schedule::GetCurrentShow($timeNow);
$current_group_id = $current[0]["group_id"];
}
foreach ($previous as $item){ if (count($currentShow) > 0){
array_push($rows, array("p", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"], $dbRows = Schedule::GetCurrentShowGroupIDs($currentShow[0]["id"]);
$item["album_title"], "x" , $item["name"], ($item["group_id"] == $current_group_id ? $item["background_color"] : ""), $item["group_id"])); $groupIDs = array();
foreach ($dbRows as $row){
array_push($groupIDs, $row["group_id"]);
}
} }
$previous = Schedule::GetPreviousItems($timeNow, 1);
$current = Schedule::GetCurrentlyPlaying($timeNow);
$next = Schedule::GetNextItems($timeNow, 10);
$rows = array();
foreach ($previous as $item){
$color = (count($currentShow) > 0) && in_array($item["group_id"], $groupIDs) ? "x" : "";
array_push($rows, array("p", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
$item["album_title"], "x" , $item["name"], $color, $item["group_id"]));
}
foreach ($current as $item){ foreach ($current as $item){
array_push($rows, array("c", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"], array_push($rows, array("c", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
$item["album_title"], "x" , $item["name"], $item["background_color"], $item["group_id"])); $item["album_title"], "x" , $item["name"], "", $item["group_id"]));
} }
foreach ($next as $item){ foreach ($next as $item){
$color = (count($currentShow) > 0) && in_array($item["group_id"], $groupIDs) ? "x" : "";
array_push($rows, array("n", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"], array_push($rows, array("n", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
$item["album_title"], "x" , $item["name"], ($item["group_id"] == $current_group_id ? $item["background_color"] : ""), $item["group_id"])); $item["album_title"], "x" , $item["name"], $color, $item["group_id"]));
} }
$data = array("columnHeaders"=>$columnHeaders, "rows"=>$rows);
return array("columnHeaders"=>$columnHeaders, "rows"=>$rows); return $data;
} }
} }

View File

@ -170,12 +170,12 @@ class ScheduleGroup {
return $this->add($startTime, $p_audioFileId); return $this->add($startTime, $p_audioFileId);
} }
public function addPlaylistAfter($p_groupId, $p_playlistId) { public function addPlaylistAfter($p_groupId, $p_playlistId) {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
// Get the end time for the given entry // Get the end time for the given entry
$sql = "SELECT MAX(ends) FROM ".$CC_CONFIG["scheduleTable"] $sql = "SELECT MAX(ends) FROM ".$CC_CONFIG["scheduleTable"]
." WHERE group_id=$p_groupId"; ." WHERE group_id=$p_groupId";
$startTime = $CC_DBC->GetOne($sql); $startTime = $CC_DBC->GetOne($sql);
return $this->add($startTime, null, $p_playlistId); return $this->add($startTime, null, $p_playlistId);
} }
@ -278,80 +278,80 @@ class Schedule {
return ($count == '0'); return ($count == '0');
} }
public static function getTimeUnScheduledInRange($s_datetime, $e_datetime) { public static function getTimeUnScheduledInRange($s_datetime, $e_datetime) {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$sql = "SELECT timestamp '{$s_datetime}' > timestamp '{$e_datetime}'"; $sql = "SELECT timestamp '{$s_datetime}' > timestamp '{$e_datetime}'";
$isNextDay = $CC_DBC->GetOne($sql); $isNextDay = $CC_DBC->GetOne($sql);
if($isNextDay === 't') { if($isNextDay === 't') {
$sql = "SELECT date '{$e_datetime}' + interval '1 day'"; $sql = "SELECT date '{$e_datetime}' + interval '1 day'";
$e_datetime = $CC_DBC->GetOne($sql); $e_datetime = $CC_DBC->GetOne($sql);
} }
$sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]." $sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]."
WHERE (starts >= '{$s_datetime}') WHERE (starts >= '{$s_datetime}')
AND (ends <= '{$e_datetime}')"; AND (ends <= '{$e_datetime}')";
$time = $CC_DBC->GetOne($sql); $time = $CC_DBC->GetOne($sql);
if(is_null($time)) if(is_null($time))
$time = 0; $time = 0;
$sql = "SELECT TIMESTAMP '{$e_datetime}' - TIMESTAMP '{$s_datetime}'"; $sql = "SELECT TIMESTAMP '{$e_datetime}' - TIMESTAMP '{$s_datetime}'";
$length = $CC_DBC->GetOne($sql); $length = $CC_DBC->GetOne($sql);
$sql = "SELECT INTERVAL '{$length}' - INTERVAL '{$time}'"; $sql = "SELECT INTERVAL '{$length}' - INTERVAL '{$time}'";
$time_left =$CC_DBC->GetOne($sql); $time_left =$CC_DBC->GetOne($sql);
return $time_left; return $time_left;
} }
public static function getTimeScheduledInRange($s_datetime, $e_datetime) { public static function getTimeScheduledInRange($s_datetime, $e_datetime) {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$sql = "SELECT timestamp '{$s_datetime}' > timestamp '{$e_datetime}'"; $sql = "SELECT timestamp '{$s_datetime}' > timestamp '{$e_datetime}'";
$isNextDay = $CC_DBC->GetOne($sql); $isNextDay = $CC_DBC->GetOne($sql);
if($isNextDay === 't') { if($isNextDay === 't') {
$sql = "SELECT date '{$e_datetime}' + interval '1 day'"; $sql = "SELECT date '{$e_datetime}' + interval '1 day'";
$e_datetime = $CC_DBC->GetOne($sql); $e_datetime = $CC_DBC->GetOne($sql);
} }
$sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]." $sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]."
WHERE (starts >= '{$s_datetime}') WHERE (starts >= '{$s_datetime}')
AND (ends <= '{$e_datetime}')"; AND (ends <= '{$e_datetime}')";
$res = $CC_DBC->GetOne($sql); $res = $CC_DBC->GetOne($sql);
if(is_null($res)) if(is_null($res))
return 0; return 0;
return $res; return $res;
} }
public static function getPercentScheduledInRange($s_datetime, $e_datetime) { public static function getPercentScheduledInRange($s_datetime, $e_datetime) {
$time = Schedule::getTimeScheduledInRange($s_datetime, $e_datetime); $time = Schedule::getTimeScheduledInRange($s_datetime, $e_datetime);
$con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME); $con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
$sql = "SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '{$s_datetime}')"; $sql = "SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '{$s_datetime}')";
$r = $con->query($sql); $r = $con->query($sql);
$s_epoch = $r->fetchColumn(0); $s_epoch = $r->fetchColumn(0);
$sql = "SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '{$e_datetime}')"; $sql = "SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '{$e_datetime}')";
$r = $con->query($sql); $r = $con->query($sql);
$e_epoch = $r->fetchColumn(0); $e_epoch = $r->fetchColumn(0);
$sql = "SELECT EXTRACT(EPOCH FROM INTERVAL '{$time}')"; $sql = "SELECT EXTRACT(EPOCH FROM INTERVAL '{$time}')";
$r = $con->query($sql); $r = $con->query($sql);
$i_epoch = $r->fetchColumn(0); $i_epoch = $r->fetchColumn(0);
$percent = ceil(($i_epoch / ($e_epoch - $s_epoch)) * 100); $percent = ceil(($i_epoch / ($e_epoch - $s_epoch)) * 100);
return $percent; return $percent;
} }
// public function onAddTrackToPlaylist($playlistId, $audioTrackId) { // public function onAddTrackToPlaylist($playlistId, $audioTrackId) {
// //
@ -387,7 +387,7 @@ class Schedule {
* "end"/"ends" (aliases to the same thing) as YYYY-MM-DD HH:MM:SS.nnnnnn * "end"/"ends" (aliases to the same thing) as YYYY-MM-DD HH:MM:SS.nnnnnn
* "group_id"/"id" (aliases to the same thing) * "group_id"/"id" (aliases to the same thing)
* "clip_length" (for audio clips this is the length of the audio clip, * "clip_length" (for audio clips this is the length of the audio clip,
* for playlists this is the length of the entire playlist) * for playlists this is the length of the entire playlist)
* "name" (playlist only) * "name" (playlist only)
* "creator" (playlist only) * "creator" (playlist only)
* "file_id" (audioclip only) * "file_id" (audioclip only)
@ -401,7 +401,7 @@ class Schedule {
* @param boolean $p_playlistsOnly * @param boolean $p_playlistsOnly
* Retrieve playlists as a single item. * Retrieve playlists as a single item.
* @return array * @return array
* Returns empty array if nothing found * Returns empty array if nothing found
*/ */
public static function GetItems($p_fromDateTime, $p_toDateTime, $p_playlistsOnly = true) { public static function GetItems($p_fromDateTime, $p_toDateTime, $p_playlistsOnly = true) {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
@ -472,24 +472,23 @@ class Schedule {
} }
$timeNow = Schedule::GetSchedulerTime(); $timeNow = Schedule::GetSchedulerTime();
return array("schedulerTime"=>gmdate("Y-m-d H:i:s"),"previous"=>Schedule::GetPreviousItems($timeNow), return array("schedulerTime"=>gmdate("Y-m-d H:i:s"),
"current"=>Schedule::GetCurrentlyPlaying($timeNow), "previous"=>Schedule::GetPreviousItems($timeNow),
"current"=>Schedule::GetCurrentlyPlaying($timeNow),
"next"=>Schedule::GetNextItems($timeNow), "next"=>Schedule::GetNextItems($timeNow),
"showStartEndTime"=>Schedule::GetCurrentShow($timeNow),
"timezone"=> date("T"), "timezone"=> date("T"),
"timezoneOffset"=> date("Z")); "timezoneOffset"=> date("Z"));
} }
public static function GetPreviousItems($timeNow, $prevCount = 1){ public static function GetPreviousItems($timeNow, $prevCount = 1){
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$sql = "SELECT pt.name, ft.track_title, ft.artist_name, ft.album_title, st.starts, st.ends, st.clip_length, st.group_id, sdt.start_time, sdt.end_time, showt.background_color" $sql = "SELECT pt.name, ft.track_title, ft.artist_name, ft.album_title, st.starts, st.ends, st.clip_length, st.group_id"
." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt, $CC_CONFIG[showSchedule] sst, $CC_CONFIG[showDays] sdt, $CC_CONFIG[showTable] showt" ." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt"
." WHERE st.ends < TIMESTAMP '$timeNow'" ." WHERE st.ends < TIMESTAMP '$timeNow'"
." AND st.ends > (TIMESTAMP '$timeNow' - INTERVAL '24 hours')" ." AND st.ends > (TIMESTAMP '$timeNow' - INTERVAL '24 hours')"
." AND st.playlist_id = pt.id" ." AND st.playlist_id = pt.id"
." AND st.file_id = ft.id" ." AND st.file_id = ft.id"
." AND st.group_id = sst.group_id"
." AND sdt.show_id = sst.show_id"
." AND showt.id = sst.show_id"
." ORDER BY st.starts DESC" ." ORDER BY st.starts DESC"
." LIMIT $prevCount"; ." LIMIT $prevCount";
$rows = $CC_DBC->GetAll($sql); $rows = $CC_DBC->GetAll($sql);
@ -499,40 +498,60 @@ class Schedule {
public static function GetCurrentlyPlaying($timeNow){ public static function GetCurrentlyPlaying($timeNow){
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$sql = "SELECT pt.name, ft.track_title, ft.artist_name, ft.album_title, st.starts, st.ends, st.clip_length, st.group_id, sdt.start_time, sdt.end_time, showt.background_color" $sql = "SELECT pt.name, ft.track_title, ft.artist_name, ft.album_title, st.starts, st.ends, st.clip_length, st.group_id"
." FROM $CC_CONFIG[scheduleTable] st," ." FROM $CC_CONFIG[scheduleTable] st,"
."$CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt, $CC_CONFIG[showSchedule] sst, $CC_CONFIG[showDays] sdt, $CC_CONFIG[showTable] showt" ."$CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt"
." WHERE st.starts < TIMESTAMP '$timeNow'" ." WHERE st.starts < TIMESTAMP '$timeNow'"
." AND st.ends > TIMESTAMP '$timeNow'" ." AND st.ends > TIMESTAMP '$timeNow'"
." AND st.playlist_id = pt.id" ." AND st.playlist_id = pt.id"
." AND st.file_id = ft.id" ." AND st.file_id = ft.id";
." AND st.group_id = sst.group_id"
." AND sdt.show_id = sst.show_id"
." AND showt.id = sst.show_id";
$rows = $CC_DBC->GetAll($sql); $rows = $CC_DBC->GetAll($sql);
return $rows; return $rows;
} }
public static function GetNextItems($timeNow, $nextCount = 1) { public static function GetNextItems($timeNow, $nextCount = 1) {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$sql = "SELECT pt.name, ft.track_title, ft.artist_name, ft.album_title, st.starts, st.ends, st.clip_length, st.group_id, sdt.start_time, sdt.end_time, showt.background_color" $sql = "SELECT pt.name, ft.track_title, ft.artist_name, ft.album_title, st.starts, st.ends, st.clip_length, st.group_id"
." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt, $CC_CONFIG[showSchedule] sst, $CC_CONFIG[showDays] sdt, $CC_CONFIG[showTable] showt" ." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt"
." WHERE st.starts > TIMESTAMP '$timeNow'" ." WHERE st.starts > TIMESTAMP '$timeNow'"
." AND st.ends < (TIMESTAMP '$timeNow' + INTERVAL '24 hours')" ." AND st.ends < (TIMESTAMP '$timeNow' + INTERVAL '24 hours')"
." AND st.playlist_id = pt.id" ." AND st.playlist_id = pt.id"
." AND st.file_id = ft.id" ." AND st.file_id = ft.id"
." AND st.group_id = sst.group_id"
." AND sdt.show_id = sst.show_id"
." AND showt.id = sst.show_id"
." ORDER BY st.starts" ." ORDER BY st.starts"
." LIMIT $nextCount"; ." LIMIT $nextCount";
$rows = $CC_DBC->GetAll($sql); $rows = $CC_DBC->GetAll($sql);
return $rows; return $rows;
} }
public static function GetStatus() { public static function GetCurrentShow($timeNow) {
global $CC_CONFIG, $CC_DBC;
$timestamp = preg_split("/ /", $timeNow);
$date = $timestamp[0];
$time = $timestamp[1];
$sql = "SELECT current_date + sd.start_time as start_timestamp, current_date + sd.end_time as end_timestamp, s.name, s.id"
." FROM $CC_CONFIG[showDays] sd, $CC_CONFIG[showTable] s"
." WHERE sd.show_id = s.id"
." AND sd.first_show <= DATE '$date'"
." AND sd.start_time <= TIME '$time'"
." AND sd.last_show > DATE '$date'"
." AND sd.end_time > TIME '$time'";
$rows = $CC_DBC->GetAll($sql);
return $rows;
} }
public static function GetCurrentShowGroupIDs($showID){
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT group_id"
." FROM $CC_CONFIG[showSchedule]"
." WHERE show_id = $showID";
$rows = $CC_DBC->GetAll($sql);
return $rows;
}
/** /**
* Convert a time string in the format "YYYY-MM-DD HH:mm:SS" * Convert a time string in the format "YYYY-MM-DD HH:mm:SS"
@ -637,9 +656,9 @@ class Schedule {
* Export the schedule in json formatted for pypo (the liquidsoap scheduler) * Export the schedule in json formatted for pypo (the liquidsoap scheduler)
* *
* @param string $range * @param string $range
* In the format "YYYY-MM-DD HH:mm:ss" * In the format "YYYY-MM-DD HH:mm:ss"
* @param string $source * @param string $source
* In the format "YYYY-MM-DD HH:mm:ss" * In the format "YYYY-MM-DD HH:mm:ss"
*/ */
public static function ExportRangeAsJson($p_fromDateTime, $p_toDateTime) public static function ExportRangeAsJson($p_fromDateTime, $p_toDateTime)
{ {
@ -675,8 +694,8 @@ class Schedule {
$playlists[$pkey]['schedule_id'] = $dx['group_id']; $playlists[$pkey]['schedule_id'] = $dx['group_id'];
$playlists[$pkey]['user_id'] = 0; $playlists[$pkey]['user_id'] = 0;
$playlists[$pkey]['id'] = $dx["playlist_id"]; $playlists[$pkey]['id'] = $dx["playlist_id"];
$playlists[$pkey]['start'] = Schedule::CcTimeToPypoTime($dx["start"]); $playlists[$pkey]['start'] = Schedule::CcTimeToPypoTime($dx["start"]);
$playlists[$pkey]['end'] = Schedule::CcTimeToPypoTime($dx["end"]); $playlists[$pkey]['end'] = Schedule::CcTimeToPypoTime($dx["end"]);
} }
} }
@ -697,13 +716,13 @@ class Schedule {
$cueOut = Schedule::WallTimeToMillisecs($item["cue_out"]); $cueOut = Schedule::WallTimeToMillisecs($item["cue_out"]);
} }
$medias[] = array( $medias[] = array(
'id' => $storedFile->getGunid(), //$item["file_id"], 'id' => $storedFile->getGunid(), //$item["file_id"],
'uri' => $uri, 'uri' => $uri,
'fade_in' => Schedule::WallTimeToMillisecs($item["fade_in"]), 'fade_in' => Schedule::WallTimeToMillisecs($item["fade_in"]),
'fade_out' => Schedule::WallTimeToMillisecs($item["fade_out"]), 'fade_out' => Schedule::WallTimeToMillisecs($item["fade_out"]),
'fade_cross' => 0, 'fade_cross' => 0,
'cue_in' => Schedule::WallTimeToMillisecs($item["cue_in"]), 'cue_in' => Schedule::WallTimeToMillisecs($item["cue_in"]),
'cue_out' => $cueOut, 'cue_out' => $cueOut,
'export_source' => 'scheduler' 'export_source' => 'scheduler'
); );
} }

View File

@ -8,7 +8,6 @@
<body> <body>
<h1>An error occurred</h1> <h1>An error occurred</h1>
<h2><?php echo $this->message ?></h2> <h2><?php echo $this->message ?></h2>
<h2><?php echo "test".APPLICATION_ENV ?></h2>
<?php if ('development' == APPLICATION_ENV): ?> <?php if ('development' == APPLICATION_ENV): ?>

View File

@ -1,5 +1,9 @@
<?php <?php
//error_reporting(E_ALL|E_STRICT);
error_reporting(E_ALL);
ini_set('display_errors', 'on');
// Define path to application directory // Define path to application directory
defined('APPLICATION_PATH') defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

View File

@ -1,6 +1,5 @@
var estimatedSchedulePosixTime = -1; var estimatedSchedulePosixTime = null;
var localRemoteTimeOffset = null;
var localRemoteTimeOffset = -1;
var previousSongs = new Array(); var previousSongs = new Array();
var currentSong = new Array(); var currentSong = new Array();
@ -16,6 +15,7 @@ var songEndFunc;
var showStartPosixTime = 0; var showStartPosixTime = 0;
var showEndPosixTime = 0; var showEndPosixTime = 0;
var showLengthMs = 1; var showLengthMs = 1;
var currentShowName = "";
/* boolean flag to let us know if we should prepare to execute a function /* boolean flag to let us know if we should prepare to execute a function
* that flips the playlist to the next song. This flags purpose is to * that flips the playlist to the next song. This flags purpose is to
@ -50,23 +50,18 @@ function getTrackInfo(song){
} }
function secondsTimer(){ function secondsTimer(){
var date = new Date(); if (localRemoteTimeOffset != null){
if (localRemoteTimeOffset != -1) var date = new Date();
estimatedSchedulePosixTime = date.getTime() - localRemoteTimeOffset; estimatedSchedulePosixTime = date.getTime() - localRemoteTimeOffset;
updateProgressBarValue(); updateProgressBarValue();
}
} setTimeout(secondsTimer, uiUpdateInterval);
function updateGlobalValues(obj){
showStartPosixTime = obj.showStartPosixTime;
showEndPosixTime = obj.showEndPosixTime;
showLengthMs = showEndPosixTime - showStartPosixTime;
} }
function newSongStart(){ function newSongStart(){
nextSongPrepare = true; nextSongPrepare = true;
currentSong[0] = nextSongs.shift(); currentSong[0] = nextSongs.shift();
updateGlobalValues(currentSong[0]); //updateGlobalValues(currentSong[0]);
updatePlaybar(); updatePlaybar();
notifySongEndListener(); notifySongEndListener();
@ -74,39 +69,36 @@ function newSongStart(){
/* Called every "uiUpdateInterval" mseconds. */ /* Called every "uiUpdateInterval" mseconds. */
function updateProgressBarValue(){ function updateProgressBarValue(){
if (estimatedSchedulePosixTime != -1){ if (showStartPosixTime != 0){
if (showStartPosixTime != 0){ var showPercentDone = (estimatedSchedulePosixTime - showStartPosixTime)/showLengthMs*100;
var showPercentDone = (estimatedSchedulePosixTime - showStartPosixTime)/showLengthMs*100; if (showPercentDone < 0 || showPercentDone > 100){
if (showPercentDone < 0 || showPercentDone > 100){ showPercentDone = 0;
showPercentDone = 0; $('#on-air-info').attr("class", "on-air-info off");
$('#on-air-info').attr("class", "on-air-info off"); } else {
} else { $('#on-air-info').attr("class", "on-air-info on");
$('#on-air-info').attr("class", "on-air-info on"); }
} $('#progress-show').attr("style", "width:"+showPercentDone+"%");
$('#progress-show').attr("style", "width:"+showPercentDone+"%"); }
}
var songPercentDone = 0; var songPercentDone = 0;
if (currentSong.length > 0){ if (currentSong.length > 0){
songPercentDone = (estimatedSchedulePosixTime - currentSong[0].songStartPosixTime)/currentSong[0].songLengthMs*100; songPercentDone = (estimatedSchedulePosixTime - currentSong[0].songStartPosixTime)/currentSong[0].songLengthMs*100;
if (songPercentDone < 0 || songPercentDone > 100){ if (songPercentDone < 0 || songPercentDone > 100){
songPercentDone = 0; songPercentDone = 0;
currentSong = new Array(); currentSong = new Array();
} }
} }
$('#progress-bar').attr("style", "width:"+songPercentDone+"%"); $('#progress-bar').attr("style", "width:"+songPercentDone+"%");
//calculate how much time left to next song if there is any //calculate how much time left to next song if there is any
if (nextSongs.length > 0 && nextSongPrepare){ if (nextSongs.length > 0 && nextSongPrepare){
if (nextSongs[0].songStartPosixTime - estimatedSchedulePosixTime < serverUpdateInterval){ if (nextSongs[0].songStartPosixTime - estimatedSchedulePosixTime < serverUpdateInterval){
nextSongPrepare = false; nextSongPrepare = false;
setTimeout(newSongStart, nextSongs[0].songStartPosixTime - estimatedSchedulePosixTime); setTimeout(newSongStart, nextSongs[0].songStartPosixTime - estimatedSchedulePosixTime);
} }
} }
updatePlaybar(); updatePlaybar();
}
setTimeout(secondsTimer, uiUpdateInterval);
} }
function updatePlaybar(){ function updatePlaybar(){
@ -149,9 +141,8 @@ function updatePlaybar(){
/* Column 1 update */ /* Column 1 update */
$('#playlist').text("Current Show:"); $('#playlist').text("Current Show:");
for (var i=0; i<currentSong.length; i++){ $('#playlist').text(currentShowName);
$('#playlist').text(currentSong[i].name);
}
$('#show-length').empty(); $('#show-length').empty();
if (estimatedSchedulePosixTime < showEndPosixTime){ if (estimatedSchedulePosixTime < showEndPosixTime){
$('#show-length').text(convertDateToHHMMSS(showStartPosixTime) + " - " + convertDateToHHMMSS(showEndPosixTime)); $('#show-length').text(convertDateToHHMMSS(showStartPosixTime) + " - " + convertDateToHHMMSS(showEndPosixTime));
@ -167,23 +158,19 @@ function calcAdditionalData(currentItem, bUpdateGlobalValues){
currentItem[i].songEndPosixTime = convertDateToPosixTime(currentItem[i].ends); currentItem[i].songEndPosixTime = convertDateToPosixTime(currentItem[i].ends);
currentItem[i].songLengthMs = currentItem[i].songEndPosixTime - currentItem[i].songStartPosixTime; currentItem[i].songLengthMs = currentItem[i].songEndPosixTime - currentItem[i].songStartPosixTime;
currentItem[i].showStartPosixTime = convertDateToPosixTime(currentItem[i].starts.substring(0, currentItem[i].starts.indexOf(" ")) + " " + currentItem[i].start_time);
currentItem[i].showEndPosixTime = convertDateToPosixTime(currentItem[i].starts.substring(0, currentItem[i].starts.indexOf(" ")) + " " + currentItem[i].end_time);
//check if there is a rollover past midnight
if (currentItem[i].start_time > currentItem[i].end_time){
//start_time is greater than end_time, so we rolled through midnight.
currentItem[i].showEndPosixTime += (1000*3600*24); //add 24 hours
}
currentItem[i].showLengthMs = currentItem[i].showEndPosixTime - currentItem[i].showStartPosixTime; currentItem[i].showLengthMs = currentItem[i].showEndPosixTime - currentItem[i].showStartPosixTime;
if (bUpdateGlobalValues){
updateGlobalValues(currentItem[i]);
}
} }
} }
function updateGlobalValues(obj){
if (obj.showStartEndTime.length > 0){
showStartPosixTime = convertDateToPosixTime(obj.showStartEndTime[0].start_timestamp);
showEndPosixTime = convertDateToPosixTime(obj.showStartEndTime[0].end_timestamp);
showLengthMs = showEndPosixTime - showStartPosixTime;
currentShowName = obj.showStartEndTime[0].name;
}
}
function parseItems(obj){ function parseItems(obj){
var schedulePosixTime = convertDateToPosixTime(obj.schedulerTime); var schedulePosixTime = convertDateToPosixTime(obj.schedulerTime);
schedulePosixTime += parseInt(obj.timezoneOffset)*1000; schedulePosixTime += parseInt(obj.timezoneOffset)*1000;
@ -193,18 +180,29 @@ function parseItems(obj){
previousSongs = obj.previous; previousSongs = obj.previous;
currentSong = obj.current; currentSong = obj.current;
nextSongs = obj.next; nextSongs = obj.next;
updateGlobalValues(obj);
calcAdditionalData(previousSongs, false); calcAdditionalData(previousSongs);
calcAdditionalData(currentSong, true); calcAdditionalData(currentSong);
calcAdditionalData(nextSongs, false); calcAdditionalData(nextSongs);
if (estimatedSchedulePosixTime == -1){ if (localRemoteTimeOffset == null){
var date = new Date(); var date = new Date();
localRemoteTimeOffset = date.getTime() - schedulePosixTime; localRemoteTimeOffset = date.getTime() - schedulePosixTime;
estimatedSchedulePosixTime = schedulePosixTime;
} }
} }
function getScheduleFromServerDebug(){
$.ajax({ url: "/Schedule/get-current-playlist/format/json", dataType:"text", success:function(data){
alert(data);
}});
setTimeout(getScheduleFromServer, serverUpdateInterval);
}
function getScheduleFromServer(){ function getScheduleFromServer(){
$.ajax({ url: "/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){ $.ajax({ url: "/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){
parseItems(data.entries); parseItems(data.entries);
@ -212,12 +210,14 @@ function getScheduleFromServer(){
setTimeout(getScheduleFromServer, serverUpdateInterval); setTimeout(getScheduleFromServer, serverUpdateInterval);
} }
function init() { function init() {
//begin producer "thread" //begin producer "thread"
getScheduleFromServer(); getScheduleFromServer();
//getScheduleFromServerDebug();
//begin consumer "thread" //begin consumer "thread"
updateProgressBarValue(); secondsTimer();
} }
function popup(mylink){ function popup(mylink){
@ -233,6 +233,5 @@ function popup(mylink){
} }
$(document).ready(function() { $(document).ready(function() {
//initialize the playlist bar in the included playlist.js
init(); init();
}); });