SAAS-675: Implement "auto" mode
This commit is contained in:
parent
3d2b189dba
commit
d0f7f820a7
|
@ -39,9 +39,26 @@ class EmbeddablePlayerController extends Zend_Controller_Action
|
|||
$this->view->station_name = Application_Model_Preference::GetStationName();
|
||||
$stream = $request->getParam('stream');
|
||||
$streamData = Application_Model_StreamSetting::getEnabledStreamData();
|
||||
$selectedStreamData = $streamData[$stream];
|
||||
$this->view->streamURL = $selectedStreamData["url"];
|
||||
$this->view->codec = $selectedStreamData["codec"];
|
||||
$this->view->displayMetadata = $request->getParam('display_metadata');
|
||||
|
||||
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];
|
||||
$this->view->streamURL = $selectedStreamData["url"];
|
||||
$this->view->codec = $selectedStreamData["codec"];
|
||||
}
|
||||
//$this->view->displayMetadata = $request->getParam('display_metadata');
|
||||
}
|
||||
}
|
|
@ -8,19 +8,42 @@
|
|||
<script type="text/javascript">
|
||||
|
||||
var MusesPlayer = function() {
|
||||
MRP.insert({
|
||||
'url':"<?php echo $this->streamURL ?>",
|
||||
'codec':"<?php echo $this->codec ?>",
|
||||
'volume':100,
|
||||
'jsevents':true,
|
||||
'autoplay':false,
|
||||
'buffering':5,
|
||||
'title':'test',
|
||||
'bgcolor':'#FFFFFF',
|
||||
'skin':'mcclean',
|
||||
'width':180,
|
||||
'height':60
|
||||
});
|
||||
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({
|
||||
'url': "<?php echo $this->streamURL ?>",
|
||||
'codec': "<?php echo $this->codec ?>",
|
||||
'volume': 100,
|
||||
'jsevents': true,
|
||||
'autoplay': false,
|
||||
'buffering': 5,
|
||||
'title': 'test',
|
||||
'bgcolor': '#FFFFFF',
|
||||
'skin': 'mcclean',
|
||||
'width': 180,
|
||||
'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?>");
|
||||
|
||||
this.flashDetect = FlashDetect.versionAtLeast(10, 1) ? true : false;
|
||||
|
@ -28,6 +51,49 @@
|
|||
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() {
|
||||
this.flashDetect ? MRP.play() : musesHTMLPlayClick();
|
||||
togglePlayStopButton();
|
||||
|
@ -46,9 +112,20 @@
|
|||
//TODO
|
||||
};
|
||||
|
||||
/*function musesCallback(event,value){
|
||||
console.log('event: "'+event+'", value: "'+value+'"');
|
||||
}*/
|
||||
function musesCallback(event,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
|
||||
|
@ -83,18 +160,35 @@
|
|||
data: {type:"interval",limit:"5"},
|
||||
dataType: "jsonp",
|
||||
success: function(data) {
|
||||
var current_track_end_time = new Date(data.current.ends);
|
||||
var current_time = new Date();
|
||||
current_time = new Date(current_time.getTime() + current_time.getTimezoneOffset()*60*1000);
|
||||
time_to_next_track_starts = current_track_end_time - current_time;
|
||||
// maybe we should set time_to_next_track_starts to
|
||||
// (10 || 20 || etc.) minutes if its greater than that
|
||||
// in case of on-the-fly schedule changes
|
||||
//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_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);
|
||||
//TODO stop the first settimeout from executing!!
|
||||
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
|
||||
// (10 || 20 || etc.) minutes if its greater than that
|
||||
// in case of on-the-fly schedule changes
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (data.next === null) {
|
||||
$("ul.schedule_list").find("li").html("Nothing scheduled");
|
||||
} else {
|
||||
$("ul.schedule_list").find("li").html(data.next.name);
|
||||
}
|
||||
|
||||
var artist = data.current.name.split(" - ")[0];
|
||||
var track = data.current.name.split(" - ")[1];
|
||||
$("p.now_playing").html(artist+"<span>"+track+"</span>");
|
||||
$("ul.schedule_list").find("li").html(data.next.name);
|
||||
}
|
||||
});
|
||||
setTimeout(getMetadata, time_to_next_track_starts);
|
||||
|
@ -141,7 +235,7 @@
|
|||
<div class="airtime_schedule">
|
||||
<p class="airtime_next">Next</p>
|
||||
<ul class="schedule_list">
|
||||
<li>John Legend - Ordinary People</li>
|
||||
<li></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue