Merge branch 'master' of dev.sourcefabric.org:campcaster
This commit is contained in:
commit
c4053a1b38
|
@ -74,7 +74,7 @@ $pages = array(
|
|||
'label' => 'Now Playing',
|
||||
'module' => 'default',
|
||||
'controller' => 'Schedule',
|
||||
'action' => 'get-scheduler-time'
|
||||
'action' => 'view-playlist'
|
||||
),
|
||||
array(
|
||||
'label' => 'Schedule',
|
||||
|
|
|
@ -175,8 +175,9 @@ class ScheduleController extends Zend_Controller_Action
|
|||
}
|
||||
}
|
||||
|
||||
public function getSchedulerTimeAction()
|
||||
public function viewPlaylistAction()
|
||||
{
|
||||
$this->view->headScript()->appendFile('/js/playlist/playlist.js','text/javascript');
|
||||
$this->view->headScript()->appendFile('/js/progressbar/jquery.progressbar.min.js','text/javascript');
|
||||
}
|
||||
|
||||
|
|
|
@ -452,7 +452,7 @@ class Schedule {
|
|||
$sql = "SELECT * FROM $CC_CONFIG[scheduleTable], $CC_CONFIG[filesTable]"
|
||||
." WHERE ($CC_CONFIG[scheduleTable].ends < TIMESTAMP '$timeNow')"
|
||||
." AND ($CC_CONFIG[scheduleTable].file_id = $CC_CONFIG[filesTable].id)"
|
||||
." ORDER BY $CC_CONFIG[scheduleTable].id"
|
||||
." ORDER BY $CC_CONFIG[scheduleTable].starts DESC"
|
||||
." LIMIT $prevCount";
|
||||
$rows = $CC_DBC->GetAll($sql);
|
||||
return $rows;
|
||||
|
@ -474,7 +474,7 @@ class Schedule {
|
|||
$sql = "SELECT * FROM $CC_CONFIG[scheduleTable], $CC_CONFIG[filesTable]"
|
||||
." WHERE ($CC_CONFIG[scheduleTable].starts > TIMESTAMP '$timeNow')"
|
||||
." AND ($CC_CONFIG[scheduleTable].file_id = $CC_CONFIG[filesTable].id)"
|
||||
." ORDER BY $CC_CONFIG[scheduleTable].id"
|
||||
." ORDER BY $CC_CONFIG[scheduleTable].starts"
|
||||
." LIMIT $nextCount";
|
||||
$rows = $CC_DBC->GetAll($sql);
|
||||
return $rows;
|
||||
|
|
|
@ -1,110 +0,0 @@
|
|||
<div>
|
||||
<script>
|
||||
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 = 0;
|
||||
var msec = 0;
|
||||
if (s.length >= 20){
|
||||
sec = s.substring(17, 19);
|
||||
msec = s.substring(20);
|
||||
} else {
|
||||
sec = s.substring(17);
|
||||
}
|
||||
|
||||
return Date.UTC(year, month, day, hour, minute, sec, msec);
|
||||
}
|
||||
|
||||
var schedulePosixTime;
|
||||
|
||||
var previousSong;
|
||||
var currentSong;
|
||||
var nextSong;
|
||||
|
||||
var updatedSchedule = false;
|
||||
|
||||
function secondsTimer(){
|
||||
schedulePosixTime += 1000;
|
||||
updateProgressBarValue();
|
||||
}
|
||||
|
||||
function updateProgressBarValue(){
|
||||
var percentDone = (schedulePosixTime - currentSong.songStartPosixTime)/currentSong.songLengthMs*100;
|
||||
if (percentDone <= 100){
|
||||
$('#spaceused1').progressBar(percentDone);
|
||||
setTimeout(secondsTimer, 1000);
|
||||
|
||||
if (!updatedSchedule && (currentSong.songEndPosixTime - schedulePosixTime < 5000)){
|
||||
updatedSchedule = true;
|
||||
getScheduleFromServer();
|
||||
}
|
||||
} else {
|
||||
currentSong = nextSong;
|
||||
updatedSchedule = false;
|
||||
}
|
||||
}
|
||||
|
||||
function getCurrentPlayingItem(currentItem){
|
||||
var songStartPosixTime = convertDateToPosixTime(currentItem.starts);
|
||||
var songEndPosixTime = convertDateToPosixTime(currentItem.ends);
|
||||
|
||||
return {songLengthMs:songEndPosixTime-songStartPosixTime, songStartPosixTime:songStartPosixTime, songEndPosixTime:songEndPosixTime};
|
||||
|
||||
}
|
||||
|
||||
function prepareNextPlayingItem(obj){
|
||||
if (obj.next.length > 0){
|
||||
var nextItem = obj.next[0];
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(obj){
|
||||
schedulePosixTime = convertDateToPosixTime(obj.schedulerTime);
|
||||
if (obj.previous.length > 0){
|
||||
previousSong = getCurrentPlayingItem(obj.previous[0]);
|
||||
$("#previous").html(obj.schedulerTime + " " + schedulePosixTime + "<br>" +
|
||||
obj.previous[0].clip_length + " " + previousSong.songLengthMs + "<br>" +
|
||||
obj.previous[0].starts + " " + previousSong.songStartPosixTime + "<br>" +
|
||||
obj.previous[0].ends + " " + previousSong.songEndPosixTime + "<br>" +
|
||||
obj.previous[0].name + "<br>");
|
||||
}
|
||||
if (obj.current.length > 0){
|
||||
currentSong = getCurrentPlayingItem(obj.current[0]);
|
||||
$("#current").html(obj.schedulerTime + " " + schedulePosixTime + "<br>" +
|
||||
obj.current[0].clip_length + " " + currentSong.songLengthMs + "<br>" +
|
||||
obj.current[0].starts + " " + currentSong.songStartPosixTime + "<br>" +
|
||||
obj.current[0].ends + " " + currentSong.songEndPosixTime + "<br>" +
|
||||
obj.current[0].name + "<br>");
|
||||
}
|
||||
if (obj.next.length > 0){
|
||||
nextSong = getCurrentPlayingItem(obj.next[0]);
|
||||
$("#next").html(obj.schedulerTime + " " + schedulePosixTime + "<br>" +
|
||||
obj.next[0].clip_length + " " + nextSong.songLengthMs + "<br>" +
|
||||
obj.next[0].starts + " " + nextSong.songStartPosixTime + "<br>" +
|
||||
obj.next[0].ends + " " + nextSong.songEndPosixTime + "<br>" +
|
||||
obj.next[0].name + "<br>");
|
||||
}
|
||||
updateProgressBarValue();
|
||||
}
|
||||
|
||||
function getScheduleFromServer(){
|
||||
$.ajax({ url: "/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){
|
||||
//alert(data);
|
||||
parseItems(data.entries);
|
||||
}});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$("#spaceused1").progressBar();
|
||||
getScheduleFromServer();
|
||||
});
|
||||
</script>
|
||||
<div id="previous" style="background: blue;"></div>
|
||||
<div id="current" style="background: white;"></div>
|
||||
<span class="progressBar" id="spaceused1">0%</span>
|
||||
<div id="next" style="background: yellow;"></div>
|
||||
|
||||
</div>
|
|
@ -0,0 +1,9 @@
|
|||
<div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$("#list0").playlistViewer();
|
||||
});
|
||||
</script>
|
||||
<div id="list0"></div>
|
||||
</div>
|
|
@ -0,0 +1,155 @@
|
|||
(function($) {
|
||||
// jQuery plugin definition
|
||||
$.fn.playlistViewer = function(params) {
|
||||
var cc = this;
|
||||
cc.estimatedSchedulePosixTime = -1;
|
||||
cc.schedulePosixTime;
|
||||
|
||||
cc.previousSongs;
|
||||
cc.currentSong;
|
||||
cc.nextSongs;
|
||||
|
||||
cc.currentElem;
|
||||
|
||||
// traverse all nodes
|
||||
return this.each(function() {
|
||||
// express a single node as a jQuery object
|
||||
cc.currentElem = $(this);
|
||||
|
||||
var prevDiv = document.createElement('div');
|
||||
prevDiv.setAttribute("id", "previous");
|
||||
$(cc.currentElem).append(prevDiv);
|
||||
|
||||
var currParentDiv = document.createElement('div');
|
||||
currParentDiv.setAttribute("style", "background-color:#bbbbbb;");
|
||||
$(cc.currentElem).append(currParentDiv);
|
||||
|
||||
var currDiv = document.createElement('div');
|
||||
currDiv.setAttribute("id", "current");
|
||||
$(currParentDiv).append(currDiv);
|
||||
|
||||
var nextDiv = document.createElement('div');
|
||||
nextDiv.setAttribute("id", "progressbar");
|
||||
$(currParentDiv).append(nextDiv);
|
||||
|
||||
var nextDiv = document.createElement('div');
|
||||
nextDiv.setAttribute("id", "next");
|
||||
$(cc.currentElem).append(nextDiv);
|
||||
|
||||
$('#progressbar').progressBar(0);
|
||||
|
||||
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(){
|
||||
cc.estimatedSchedulePosixTime += 1000;
|
||||
updateProgressBarValue();
|
||||
}
|
||||
|
||||
function updateProgressBarValue(){
|
||||
if (cc.estimatedSchedulePosixTime != -1){
|
||||
if (cc.currentSong.length > 0){
|
||||
var percentDone = (cc.estimatedSchedulePosixTime - cc.currentSong[0].songStartPosixTime)/cc.currentSong[0].songLengthMs*100;
|
||||
if (percentDone <= 100){
|
||||
$('#progressbar').progressBar(percentDone);
|
||||
} else {
|
||||
if (cc.nextSongs.length > 0){
|
||||
cc.currentSong[0] = cc.nextSongs.shift();
|
||||
} else {
|
||||
cc.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.
|
||||
cc.estimatedSchedulePosixTime = cc.schedulePosixTime;
|
||||
}
|
||||
} else
|
||||
$('#progressbar').progressBar(0);
|
||||
updatePlaylist();
|
||||
}
|
||||
setTimeout(secondsTimer, 1000);
|
||||
}
|
||||
|
||||
function createPlaylistElementString(song){
|
||||
return "Start time: " + song.starts + "<br>" +
|
||||
"End time: " + song.ends + "<br>" +
|
||||
"Clip length: " + song.clip_length + "<br>" +
|
||||
"Name: " + song.name + "<br>";
|
||||
}
|
||||
|
||||
function updatePlaylist(){
|
||||
$('#previous').empty();
|
||||
$('#current').empty();
|
||||
$('#next').empty();
|
||||
for (var i=0; i<cc.previousSongs.length; i++){
|
||||
var divElem = document.createElement('div');
|
||||
divElem.innerHTML = createPlaylistElementString(cc.previousSongs[i]);
|
||||
$('#previous').append(divElem);
|
||||
}
|
||||
for (var i=0; i<cc.currentSong.length; i++){
|
||||
var divElem = document.createElement('div');
|
||||
divElem.innerHTML = createPlaylistElementString(cc.currentSong[i]);
|
||||
$('#current').append(divElem);
|
||||
}
|
||||
for (var i=0; i<cc.nextSongs.length; i++){
|
||||
var divElem = document.createElement('div');
|
||||
divElem.innerHTML = createPlaylistElementString(cc.nextSongs[i]);
|
||||
$('#next').append(divElem);
|
||||
}
|
||||
}
|
||||
|
||||
function calcAdditionalData(currentItem){
|
||||
for (var i=0; i<currentItem.length; i++){
|
||||
currentItem[i].songStartPosixTime = convertDateToPosixTime(currentItem[i].starts);
|
||||
currentItem[i].songEndPosixTime = convertDateToPosixTime(currentItem[i].ends);
|
||||
currentItem[i].songLengthMs = currentItem[i].songEndPosixTime - currentItem[i].songStartPosixTime;
|
||||
}
|
||||
}
|
||||
|
||||
function prepareNextPlayingItem(obj){
|
||||
if (obj.next.length > 0){
|
||||
var nextItem = obj.next[0];
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(obj){
|
||||
cc.schedulePosixTime = convertDateToPosixTime(obj.schedulerTime);
|
||||
|
||||
if (cc.estimatedSchedulePosixTime == -1)
|
||||
cc.estimatedSchedulePosixTime = cc.schedulePosixTime;
|
||||
|
||||
cc.previousSongs = obj.previous;
|
||||
cc.currentSong = obj.current;
|
||||
cc.nextSongs = obj.next;
|
||||
|
||||
calcAdditionalData(cc.previousSongs);
|
||||
calcAdditionalData(cc.currentSong);
|
||||
calcAdditionalData(cc.nextSongs);
|
||||
}
|
||||
|
||||
function getScheduleFromServer(){
|
||||
$.ajax({ url: "http://localhost/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){
|
||||
parseItems(data.entries);
|
||||
}});
|
||||
setTimeout(getScheduleFromServer, 5000);
|
||||
}
|
||||
|
||||
};
|
||||
})(jQuery);
|
Loading…
Reference in New Issue