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();
|
$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();
|
||||||
$selectedStreamData = $streamData[$stream];
|
|
||||||
$this->view->streamURL = $selectedStreamData["url"];
|
if ($stream == "auto") {
|
||||||
$this->view->codec = $selectedStreamData["codec"];
|
$this->view->playerMode = "auto";
|
||||||
$this->view->displayMetadata = $request->getParam('display_metadata');
|
$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">
|
<script type="text/javascript">
|
||||||
|
|
||||||
var MusesPlayer = function() {
|
var MusesPlayer = function() {
|
||||||
MRP.insert({
|
this.mobileDetect = this.mobileDetect();
|
||||||
'url':"<?php echo $this->streamURL ?>",
|
this.availableMobileStreamQueue = <?php echo $this->availableMobileStreams?>;
|
||||||
'codec':"<?php echo $this->codec ?>",
|
this.availableDesktopStreamQueue = <?php echo $this->availableDesktopStreams?>;
|
||||||
'volume':100,
|
this.playerMode = "<?php echo $this->playerMode ?>";
|
||||||
'jsevents':true,
|
|
||||||
'autoplay':false,
|
if (this.playerMode == "manual") {
|
||||||
'buffering':5,
|
MRP.insert({
|
||||||
'title':'test',
|
'url': "<?php echo $this->streamURL ?>",
|
||||||
'bgcolor':'#FFFFFF',
|
'codec': "<?php echo $this->codec ?>",
|
||||||
'skin':'mcclean',
|
'volume': 100,
|
||||||
'width':180,
|
'jsevents': true,
|
||||||
'height':60
|
'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?>");
|
$("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,18 +160,35 @@
|
||||||
data: {type:"interval",limit:"5"},
|
data: {type:"interval",limit:"5"},
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
var current_track_end_time = new Date(data.current.ends);
|
//console.log("hello");
|
||||||
var current_time = new Date();
|
|
||||||
current_time = new Date(current_time.getTime() + current_time.getTimezoneOffset()*60*1000);
|
if (data.current === null) {
|
||||||
time_to_next_track_starts = current_track_end_time - current_time;
|
$("p.now_playing").html("Offline");
|
||||||
// maybe we should set time_to_next_track_starts to
|
} else {
|
||||||
// (10 || 20 || etc.) minutes if its greater than that
|
var artist = data.current.name.split(" - ")[0];
|
||||||
// in case of on-the-fly schedule changes
|
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);
|
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>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue