diff --git a/application/Bootstrap.php b/application/Bootstrap.php index 3a7c5b214..92947e49b 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -53,6 +53,8 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $view = $this->getResource('view'); $view->headScript()->appendFile('/js/libs/jquery-1.4.4.min.js','text/javascript'); $view->headScript()->appendFile('/js/libs/jquery-ui-1.8.8.custom.min.js','text/javascript'); + $view->headScript()->appendFile('/js/progressbar/jquery.progressbar.min.js','text/javascript'); + $view->headScript()->appendFile('/js/playlist/playlist.js','text/javascript'); } } diff --git a/application/controllers/NowplayingController.php b/application/controllers/NowplayingController.php index fb30479de..d9f323335 100644 --- a/application/controllers/NowplayingController.php +++ b/application/controllers/NowplayingController.php @@ -11,14 +11,13 @@ class NowplayingController extends Zend_Controller_Action public function indexAction() { - $this->view->headScript()->appendFile('/js/playlist/playlist.js','text/javascript'); $this->view->headScript()->appendFile('/js/datatables/js/jquery.dataTables.min.js','text/javascript'); - $this->view->headScript()->appendFile('/js/progressbar/jquery.progressbar.min.js','text/javascript'); + $this->view->headLink()->appendStylesheet('/css/datatables/css/demo_page.css'); $this->view->headLink()->appendStylesheet('/css/datatables/css/demo_table.css'); - $this->_helper->viewRenderer->setResponseSegment('nowplaying'); + //$this->_helper->viewRenderer->setResponseSegment('nowplaying'); } public function getDataGridDataAction() diff --git a/application/layouts/scripts/layout.phtml b/application/layouts/scripts/layout.phtml index 768cda63b..7297c6513 100644 --- a/application/layouts/scripts/layout.phtml +++ b/application/layouts/scripts/layout.phtml @@ -9,7 +9,7 @@ -
layout()->nowplaying ?>
+
partial('partialviews/header.phtml') ?>
layout()->content ?>
diff --git a/application/models/Nowplaying.php b/application/models/Nowplaying.php index c704c9a0f..0dbb3933e 100644 --- a/application/models/Nowplaying.php +++ b/application/models/Nowplaying.php @@ -21,14 +21,14 @@ class Application_Model_Nowplaying $rows = array(); foreach ($previous as $item){ - array_push($rows, array(substr($item["starts"], 0, strpos($item["starts"], " ")), $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"], + array_push($rows, array($item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"], $item["album_title"], "x" , "y")); } foreach ($current as $item){ array_push($rows, array($item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"], - $item["album_title"], "x" , "y")); + $item["album_title"], "x" , "y")); } foreach ($next as $item){ diff --git a/application/models/Schedule.php b/application/models/Schedule.php index 715006b2c..6adae79bf 100644 --- a/application/models/Schedule.php +++ b/application/models/Schedule.php @@ -502,9 +502,10 @@ class Schedule { public static function GetNextItems($timeNow, $nextCount = 1) { global $CC_CONFIG, $CC_DBC; - $sql = "SELECT * FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft" + $sql = "SELECT *, pt.name as playlistName FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt" ." WHERE (st.starts > TIMESTAMP '$timeNow')" ." AND (st.file_id = ft.id)" + ." AND (st.playlist_id = pt.id)" ." ORDER BY st.starts" ." LIMIT $nextCount"; $rows = $CC_DBC->GetAll($sql); diff --git a/application/views/scripts/nowplaying/index.phtml b/application/views/scripts/nowplaying/index.phtml index cccadd021..049701146 100644 --- a/application/views/scripts/nowplaying/index.phtml +++ b/application/views/scripts/nowplaying/index.phtml @@ -1,29 +1,42 @@ -
-
Listen
-
Volume
-
- -
-
Show:
-
Playlist:
-
Host:
-
- -
-
Previous:
-
Current:
-
Upcoming:
-
- -
-
Start:
-
End:
-
|
-
diff --git a/application/views/scripts/partialviews/header.phtml b/application/views/scripts/partialviews/header.phtml new file mode 100644 index 000000000..a005293ba --- /dev/null +++ b/application/views/scripts/partialviews/header.phtml @@ -0,0 +1,42 @@ +
+
Listen
+
+ +
+
Show:
+
Playlist:
+
Host:
+
+ +
+
Previous:
+
Current:
+
Upcoming:
+
+ +
+
Start:
+
End:
+
|
+ + + + + diff --git a/public/js/playlist/playlist.js b/public/js/playlist/playlist.js index 7956f5d76..32c334e73 100644 --- a/public/js/playlist/playlist.js +++ b/public/js/playlist/playlist.js @@ -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 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(); + } diff --git a/pypo/test/airtime-schedule-insert.php b/pypo/test/airtime-schedule-insert.php index 57bcbd78c..1a5ce3e93 100644 --- a/pypo/test/airtime-schedule-insert.php +++ b/pypo/test/airtime-schedule-insert.php @@ -41,7 +41,7 @@ echo "Creating new playlist '$playlistName'..."; $pl = new Playlist(); $pl->create($playlistName); -/* + // Add a media clip $mediaFile = StoredFile::findByOriginalName("ACDC_-_Back_In_Black-sample.ogg"); if (is_null($mediaFile)) { @@ -54,7 +54,6 @@ if (is_null($mediaFile)) { } } $pl->addAudioClip($mediaFile->getId()); -*/ $mediaFile = StoredFile::findByOriginalName("Peter_Rudenko_-_Opening.mp3"); if (is_null($mediaFile)) { @@ -69,6 +68,20 @@ if (is_null($mediaFile)) { $pl->addAudioClip($mediaFile->getId()); echo "done.\n"; +$mediaFile = StoredFile::findByOriginalName("Manolo Camp - Morning Coffee.mp3"); +if (is_null($mediaFile)) { + echo "Adding test audio clip to the database.\n"; + $v = array("filepath" => __DIR__."/../../audio_samples/OpSound/Manolo Camp - Morning Coffee.mp3"); + $mediaFile = StoredFile::Insert($v); + if (PEAR::isError($mediaFile)) { + var_dump($mediaFile); + exit(); + } +} +$pl->addAudioClip($mediaFile->getId()); +echo "done.\n"; + + //$pl2 = Playlist::findPlaylistByName("pypo_playlist_test"); //var_dump($pl2); @@ -91,7 +104,8 @@ echo "done.\n"; // Schedule the playlist for two minutes from now echo "Scheduling new playlist...\n"; -$playTime = date("Y-m-d H:i:s", time()+(60*$minutesFromNow)); +//$playTime = date("Y-m-d H:i:s", time()+(60*$minutesFromNow)); +$playTime = date("Y-m-d H:i:s", time()+(20*$minutesFromNow)); $scheduleGroup = new ScheduleGroup(); $scheduleGroup->add($playTime, null, $pl->getId());