-synchronize
This commit is contained in:
parent
8404fa4145
commit
ffa508de34
3 changed files with 148 additions and 140 deletions
|
@ -178,6 +178,7 @@ class ScheduleController extends Zend_Controller_Action
|
||||||
public function getSchedulerTimeAction()
|
public function getSchedulerTimeAction()
|
||||||
{
|
{
|
||||||
$this->view->headScript()->appendFile('/js/playlist/playlist.js','text/javascript');
|
$this->view->headScript()->appendFile('/js/playlist/playlist.js','text/javascript');
|
||||||
|
$this->view->headScript()->appendFile('/js/progressbar/jquery.progressbar.min.js','text/javascript');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCurrentPlaylistAction()
|
public function getCurrentPlaylistAction()
|
||||||
|
|
|
@ -6,5 +6,5 @@
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<div id="list0"></div>
|
<div id="list0"></div>
|
||||||
|
<div id="spaceused1"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,142 +1,149 @@
|
||||||
(function($) {
|
(function($) {
|
||||||
// jQuery plugin definition
|
// jQuery plugin definition
|
||||||
$.fn.playlistViewer = function(params) {
|
$.fn.playlistViewer = function(params) {
|
||||||
// merge default and user parameters
|
var cc = this;
|
||||||
params = $.extend( {minlength: 0, maxlength: 99999}, params);
|
cc.estimatedSchedulePosixTime = -1;
|
||||||
|
cc.schedulePosixTime;
|
||||||
|
|
||||||
|
cc.previousSongs;
|
||||||
var $t;
|
cc.currentSong;
|
||||||
|
cc.nextSongs;
|
||||||
// traverse all nodes
|
|
||||||
return this.each(function() {
|
|
||||||
// express a single node as a jQuery object
|
|
||||||
$t = $(this);
|
|
||||||
|
|
||||||
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 = 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 estimatedSchedulePosixTime = -1;
|
|
||||||
var schedulePosixTime;
|
|
||||||
|
|
||||||
var previousSongs;
|
|
||||||
var currentSong;
|
|
||||||
var nextSongs;
|
|
||||||
|
|
||||||
function secondsTimer(){
|
|
||||||
estimatedSchedulePosixTime += 1000;
|
|
||||||
updateProgressBarValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateProgressBarValue(){
|
|
||||||
alert(estimatedSchedulePosixTime);
|
|
||||||
if (estimatedSchedulePosixTime != -1){
|
|
||||||
if (currentSong.length > 0){
|
|
||||||
var percentDone = (estimatedSchedulePosixTime - currentSong[0].songStartPosixTime)/currentSong[0].songLengthMs*100;
|
|
||||||
if (percentDone <= 100){
|
|
||||||
//$('#spaceused1').progressBar(percentDone);
|
|
||||||
} else {
|
|
||||||
if (nextSongs.length > 0){
|
|
||||||
currentSong[0] = nextSongs.shift();
|
|
||||||
} else {
|
|
||||||
currentSong = new Array();
|
|
||||||
}
|
|
||||||
//$('#spaceused1').progressBar(0);
|
|
||||||
estimatedSchedulePosixTime = schedulePosixTime;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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<previousSongs.length; i++){
|
|
||||||
//var divElem = document.createElement('div');
|
|
||||||
//divElem.innerHTML = createPlaylistElementString(previousSongs[i]);
|
|
||||||
$t.text(createPlaylistElementString(previousSongs[i]));
|
|
||||||
//$('#previous').append(divElem);
|
|
||||||
}
|
|
||||||
for (var i=0; i<currentSong.length; i++){
|
|
||||||
//var divElem = document.createElement('div');
|
|
||||||
//divElem.innerHTML = createPlaylistElementString(currentSong[i]);
|
|
||||||
//$('#current').append(divElem);
|
|
||||||
$t.text(createPlaylistElementString(currentSong[i]));
|
|
||||||
}
|
|
||||||
for (var i=0; i<nextSongs.length; i++){
|
|
||||||
//var divElem = document.createElement('div');
|
|
||||||
//divElem.innerHTML = createPlaylistElementString(nextSongs[i]);
|
|
||||||
//$('#next').append(divElem);
|
|
||||||
$t.text(createPlaylistElementString(nextSongs[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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){
|
|
||||||
schedulePosixTime = convertDateToPosixTime(obj.schedulerTime);
|
|
||||||
|
|
||||||
if (estimatedSchedulePosixTime == -1)
|
cc.currentElem;
|
||||||
estimatedSchedulePosixTime = schedulePosixTime;
|
|
||||||
|
|
||||||
previousSongs = obj.previous;
|
|
||||||
currentSong = obj.current;
|
|
||||||
nextSongs = obj.next;
|
|
||||||
|
|
||||||
calcAdditionalData(previousSongs);
|
|
||||||
calcAdditionalData(currentSong);
|
|
||||||
calcAdditionalData(nextSongs);
|
|
||||||
|
|
||||||
//updatePlaylist();
|
|
||||||
//updateProgressBarValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
function getScheduleFromServer(){
|
// traverse all nodes
|
||||||
$.ajax({ url: "http://localhost/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){
|
return this.each(function() {
|
||||||
parseItems(data.entries);
|
// express a single node as a jQuery object
|
||||||
}});
|
cc.currentElem = $(this);
|
||||||
setTimeout(getScheduleFromServer, 5000);
|
|
||||||
}
|
var prevDiv = document.createElement('div');
|
||||||
|
prevDiv.setAttribute("id", "previous");
|
||||||
};
|
$(cc.currentElem).append(prevDiv);
|
||||||
})(jQuery);
|
|
||||||
|
var currDiv = document.createElement('div');
|
||||||
|
currDiv.setAttribute("id", "current");
|
||||||
|
$(cc.currentElem).append(currDiv);
|
||||||
|
|
||||||
|
var nextDiv = document.createElement('div');
|
||||||
|
nextDiv.setAttribute("id", "next");
|
||||||
|
$(cc.currentElem).append(nextDiv);
|
||||||
|
|
||||||
|
$('#spaceused1').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 = 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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){
|
||||||
|
$('#spaceused1').progressBar(percentDone);
|
||||||
|
} else {
|
||||||
|
if (nextSongs.length > 0){
|
||||||
|
cc.currentSong[0] = cc.nextSongs.shift();
|
||||||
|
} else {
|
||||||
|
cc.currentSong = new Array();
|
||||||
|
}
|
||||||
|
$('#spaceused1').progressBar(0);
|
||||||
|
cc.estimatedSchedulePosixTime = cc.schedulePosixTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
//cc.currentElem.html(createPlaylistElementString(previousSongs[i]));
|
||||||
|
}
|
||||||
|
for (var i=0; i<cc.currentSong.length; i++){
|
||||||
|
var divElem = document.createElement('div');
|
||||||
|
divElem.innerHTML = createPlaylistElementString(cc.currentSong[i]);
|
||||||
|
$('#current').append(divElem);
|
||||||
|
//cc.currentElem.html(createPlaylistElementString(currentSong[i]));
|
||||||
|
}
|
||||||
|
for (var i=0; i<cc.nextSongs.length; i++){
|
||||||
|
var divElem = document.createElement('div');
|
||||||
|
divElem.innerHTML = createPlaylistElementString(cc.nextSongs[i]);
|
||||||
|
$('#next').append(divElem);
|
||||||
|
//cc.currentElem.html(createPlaylistElementString(nextSongs[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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…
Add table
Add a link
Reference in a new issue