SAAS-675: Implement "auto" mode

This commit is contained in:
drigato 2015-03-27 16:34:04 -04:00
parent 3d2b189dba
commit d0f7f820a7
2 changed files with 143 additions and 32 deletions

View File

@ -39,9 +39,26 @@ class EmbeddablePlayerController extends Zend_Controller_Action
$this->view->station_name = Application_Model_Preference::GetStationName(); $this->view->station_name = Application_Model_Preference::GetStationName();
$stream = $request->getParam('stream'); $stream = $request->getParam('stream');
$streamData = Application_Model_StreamSetting::getEnabledStreamData(); $streamData = Application_Model_StreamSetting::getEnabledStreamData();
if ($stream == "auto") {
$this->view->playerMode = "auto";
$availableMobileStreams = array();
$availableDesktopStreams = array();
foreach ($streamData as $s) {
if ($s["mobile"]) {
array_push($availableMobileStreams, $s);
} else if (!$s["mobile"]) {
array_push($availableDesktopStreams, $s);
}
}
$this->view->availableMobileStreams = json_encode($availableMobileStreams);
$this->view->availableDesktopStreams = json_encode($availableDesktopStreams);
} else {
$this->view->playerMode = "manual";
$selectedStreamData = $streamData[$stream]; $selectedStreamData = $streamData[$stream];
$this->view->streamURL = $selectedStreamData["url"]; $this->view->streamURL = $selectedStreamData["url"];
$this->view->codec = $selectedStreamData["codec"]; $this->view->codec = $selectedStreamData["codec"];
$this->view->displayMetadata = $request->getParam('display_metadata'); }
//$this->view->displayMetadata = $request->getParam('display_metadata');
} }
} }

View File

@ -8,6 +8,12 @@
<script type="text/javascript"> <script type="text/javascript">
var MusesPlayer = function() { var MusesPlayer = function() {
this.mobileDetect = this.mobileDetect();
this.availableMobileStreamQueue = <?php echo $this->availableMobileStreams?>;
this.availableDesktopStreamQueue = <?php echo $this->availableDesktopStreams?>;
this.playerMode = "<?php echo $this->playerMode ?>";
if (this.playerMode == "manual") {
MRP.insert({ MRP.insert({
'url': "<?php echo $this->streamURL ?>", 'url': "<?php echo $this->streamURL ?>",
'codec': "<?php echo $this->codec ?>", 'codec': "<?php echo $this->codec ?>",
@ -21,6 +27,23 @@
'width': 180, 'width': 180,
'height': 60 'height': 60
}); });
} else if (this.playerMode == "auto") {
var stream = this.getNextAvailableStream();
MRP.insert({
'url': stream["url"],
'codec': stream["codec"],
'volume': 100,
'jsevents': true,
'autoplay': false,
'buffering': 5,
'title': 'test',
'bgcolor': '#FFFFFF',
'skin': 'mcclean',
'width': 180,
'height': 60
});
}
$("p.station_name").html("<?php echo $this->station_name?>"); $("p.station_name").html("<?php echo $this->station_name?>");
this.flashDetect = FlashDetect.versionAtLeast(10, 1) ? true : false; this.flashDetect = FlashDetect.versionAtLeast(10, 1) ? true : false;
@ -28,6 +51,49 @@
getMetadata(); getMetadata();
}; };
MusesPlayer.prototype.mobileDetect = function() {
if ( screen.width <= 760) {
return true;
} else {
return false;
}
}
MusesPlayer.prototype.getNextAvailableStream = function() {
if (this.mobileDetect && this.availableMobileStreamQueue.length > 0) {
return this.getNextAvailableMobileStream();
}
if (!this.mobileDetect && this.availableDesktopStreamQueue.length > 0) {
return this.getNextAvailableDesktopStream();
}
//if we get to this point there are no available streams for the
//type of device the client has connected with so just return
//the next available stream - first we'll try the desktop streams
var desktopStream = this.getNextAvailableDesktopStream();
if (desktopStream) {
return desktopStream;
} else {
return this.getNextAvailableMobileStream();
}
}
MusesPlayer.prototype.getNextAvailableMobileStream = function() {
var stream = this.availableMobileStreamQueue.shift();
//add to end of queue
this.availableMobileStreamQueue.push(stream);
return stream;
}
MusesPlayer.prototype.getNextAvailableDesktopStream = function() {
var stream = this.availableDesktopStreamQueue.shift();
//add to end of queue
this.availableDesktopStreamQueue.push(stream);
return stream;
}
MusesPlayer.prototype.play = function() { MusesPlayer.prototype.play = function() {
this.flashDetect ? MRP.play() : musesHTMLPlayClick(); this.flashDetect ? MRP.play() : musesHTMLPlayClick();
togglePlayStopButton(); togglePlayStopButton();
@ -46,9 +112,20 @@
//TODO //TODO
}; };
/*function musesCallback(event,value){ function musesCallback(event,value){
console.log('event: "'+event+'", value: "'+value+'"'); switch (event) {
}*/ case "loadComplete":
// no source URL is set
if (value === "0") {
console.log("loadComplete failed");
}
case "ioError":
// connection limit reached or problem connecting to stream
if (value === "0") {
console.log("ioError");
}
}
}
/** /**
* This is a hack to trigger the play button in HTML5 mode * This is a hack to trigger the play button in HTML5 mode
@ -83,19 +160,36 @@
data: {type:"interval",limit:"5"}, data: {type:"interval",limit:"5"},
dataType: "jsonp", dataType: "jsonp",
success: function(data) { success: function(data) {
//console.log("hello");
if (data.current === null) {
$("p.now_playing").html("Offline");
} else {
var artist = data.current.name.split(" - ")[0];
var track = data.current.name.split(" - ")[1];
$("p.now_playing").html(artist + "<span>" + track + "</span>");
var current_track_end_time = new Date(data.current.ends); var current_track_end_time = new Date(data.current.ends);
var current_time = new Date(); var current_time = new Date();
//convert current_time to UTC to match the timezone of time_to_next_track_starts
current_time = new Date(current_time.getTime() + current_time.getTimezoneOffset() * 60 * 1000); current_time = new Date(current_time.getTime() + current_time.getTimezoneOffset() * 60 * 1000);
//TODO stop the first settimeout from executing!!
time_to_next_track_starts = current_track_end_time - current_time; time_to_next_track_starts = current_track_end_time - current_time;
//console.log((time_to_next_track_starts/1000)/60);
// maybe we should set time_to_next_track_starts to // maybe we should set time_to_next_track_starts to
// (10 || 20 || etc.) minutes if its greater than that // (10 || 20 || etc.) minutes if its greater than that
// in case of on-the-fly schedule changes // in case of on-the-fly schedule changes
var artist = data.current.name.split(" - ")[0];
var track = data.current.name.split(" - ")[1]; }
$("p.now_playing").html(artist+"<span>"+track+"</span>");
if (data.next === null) {
$("ul.schedule_list").find("li").html("Nothing scheduled");
} else {
$("ul.schedule_list").find("li").html(data.next.name); $("ul.schedule_list").find("li").html(data.next.name);
} }
}
}); });
setTimeout(getMetadata, time_to_next_track_starts); setTimeout(getMetadata, time_to_next_track_starts);
} }
@ -141,7 +235,7 @@
<div class="airtime_schedule"> <div class="airtime_schedule">
<p class="airtime_next">Next</p> <p class="airtime_next">Next</p>
<ul class="schedule_list"> <ul class="schedule_list">
<li>John Legend - Ordinary People</li> <li></li>
</ul> </ul>
</div> </div>