SAAS-867: Embedded player spins in endless loop if connection is refused
This commit is contained in:
parent
74b403897d
commit
1bb6ee63dc
|
@ -8,6 +8,7 @@
|
||||||
<link href='https://fonts.googleapis.com/css?family=Roboto:400,100,300,700' rel='stylesheet' type='text/css'>
|
<link href='https://fonts.googleapis.com/css?family=Roboto:400,100,300,700' rel='stylesheet' type='text/css'>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
var RETRY_DELAY_MSECS = 2000; //Delay before trying to reconnect to stream after an error.
|
||||||
var MAX_MOBILE_SCREEN_WIDTH = 760;
|
var MAX_MOBILE_SCREEN_WIDTH = 760;
|
||||||
|
|
||||||
// We are creating a custom player object that acts as a wrapper
|
// We are creating a custom player object that acts as a wrapper
|
||||||
|
@ -31,6 +32,7 @@
|
||||||
'title': 'test',
|
'title': 'test',
|
||||||
'bgcolor': '#FFFFFF',
|
'bgcolor': '#FFFFFF',
|
||||||
'skin': 'mcclean',
|
'skin': 'mcclean',
|
||||||
|
'reconnectTime' : 2000, //Doesn't seem to do anything
|
||||||
'width': 180,
|
'width': 180,
|
||||||
'height': 60
|
'height': 60
|
||||||
};
|
};
|
||||||
|
@ -64,21 +66,19 @@
|
||||||
if (!this.flashDetect) {
|
if (!this.flashDetect) {
|
||||||
|
|
||||||
MRP.html.audio.addEventListener('error', function failed(e) {
|
MRP.html.audio.addEventListener('error', function failed(e) {
|
||||||
|
var streamUrl = "";
|
||||||
|
if (musesPlayer.playerMode == "auto") {
|
||||||
|
var nextAvailableStream = musesPlayer.getNextAvailableStream();
|
||||||
|
streamUrl = nextAvailableStream["url"];
|
||||||
|
} else {
|
||||||
|
streamUrl = musesPlayer.settings.url;
|
||||||
|
}
|
||||||
|
|
||||||
switch (e.target.error.code) {
|
switch (e.target.error.code) {
|
||||||
case e.target.error.MEDIA_ERR_NETWORK:
|
case e.target.error.MEDIA_ERR_NETWORK:
|
||||||
// If there is a network error keep retrying to connect
|
// If there is a network error keep retrying to connect
|
||||||
// to a stream.
|
// to a stream.
|
||||||
var stream;
|
musesPlayer.deferredPlay(streamUrl, RETRY_DELAY_MSECS);
|
||||||
if (musesPlayer.playerMode == "auto") {
|
|
||||||
var nextAvailableStream = musesPlayer.getNextAvailableStream();
|
|
||||||
stream = nextAvailableStream["url"];
|
|
||||||
} else {
|
|
||||||
stream = musesPlayer.settings.url;
|
|
||||||
}
|
|
||||||
var audio = $(MRP.html.audio);
|
|
||||||
audio[0].src = stream;
|
|
||||||
audio[0].load();
|
|
||||||
audio[0].play();
|
|
||||||
break;
|
break;
|
||||||
case e.target.error.MEDIA_ERR_DECODE:
|
case e.target.error.MEDIA_ERR_DECODE:
|
||||||
// If there was a corruption error or a problem with the browser
|
// If there was a corruption error or a problem with the browser
|
||||||
|
@ -92,11 +92,7 @@
|
||||||
// or the max number of listeners has been reached
|
// or the max number of listeners has been reached
|
||||||
// retry connection with the next available stream.
|
// retry connection with the next available stream.
|
||||||
if (musesPlayer.playerMode == "auto") {
|
if (musesPlayer.playerMode == "auto") {
|
||||||
var nextAvailableStream = musesPlayer.getNextAvailableStream();
|
musesPlayer.deferredPlay(nextAvailableStream["url"], RETRY_DELAY_MSECS);
|
||||||
var audio = $(MRP.html.audio);
|
|
||||||
audio[0].src = nextAvailableStream["url"];;
|
|
||||||
audio[0].load();
|
|
||||||
audio[0].play();
|
|
||||||
} else {
|
} else {
|
||||||
// If in manual mode and the current stream format is not supported
|
// If in manual mode and the current stream format is not supported
|
||||||
// or the max number of listeners has been reached
|
// or the max number of listeners has been reached
|
||||||
|
@ -179,27 +175,44 @@
|
||||||
MRP.setUrl(url);
|
MRP.setUrl(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Retry playback after a few seconds (used to throttle attempts to reconnect/play). */
|
||||||
|
MusesPlayer.prototype.deferredPlay = function(streamUrl, delayMSec) {
|
||||||
|
if (!this.flashDetect) {
|
||||||
|
setTimeout(function() {
|
||||||
|
var audio = $(MRP.html.audio);
|
||||||
|
audio[0].src = streamUrl;
|
||||||
|
audio[0].load();
|
||||||
|
audio[0].play();
|
||||||
|
}, delayMSec);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
setTimeout(function() {
|
||||||
|
musesPlayer.setURL(streamUrl);
|
||||||
|
musesPlayer.play();
|
||||||
|
}, delayMSec);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// detects errors in FLASH mode
|
// detects errors in FLASH mode
|
||||||
function musesCallback(event,value) {
|
function musesCallback(event,value) {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case "ioError":
|
case "ioError":
|
||||||
// problem connecting to stream
|
// problem connecting to stream
|
||||||
var stream;
|
var streamUrl = "";
|
||||||
if (musesPlayer.playerMode == "auto") {
|
if (musesPlayer.playerMode == "auto") {
|
||||||
stream = musesPlayer.getNextAvailableStream();
|
streamUrl = musesPlayer.getNextAvailableStream()["url"];
|
||||||
musesPlayer.setURL(stream["url"]);
|
|
||||||
} else {
|
} else {
|
||||||
stream = musesPlayer.settings.url;
|
streamUrl = musesPlayer.settings.url;
|
||||||
musesPlayer.setURL(stream);
|
|
||||||
}
|
}
|
||||||
musesPlayer.play();
|
|
||||||
|
//Retry playback but only after sleeping for a bit, to avoid spinning.
|
||||||
|
musesPlayer.deferredPlay(streamUrl, RETRY_DELAY_MSECS);
|
||||||
break;
|
break;
|
||||||
case "securityError":
|
case "securityError":
|
||||||
// max listeners reached
|
// max listeners reached
|
||||||
if (musesPlayer.playerMode == "auto") {
|
if (musesPlayer.playerMode == "auto") {
|
||||||
var stream = musesPlayer.getNextAvailableStream();
|
var stream = musesPlayer.getNextAvailableStream();
|
||||||
musesPlayer.setURL(stream["url"]);
|
musesPlayer.deferredPlay(stream["url"], RETRY_DELAY_MSECS);
|
||||||
musesPlayer.play();
|
|
||||||
} else {
|
} else {
|
||||||
// If in manual mode and there is a problem connecting to
|
// If in manual mode and there is a problem connecting to
|
||||||
// the stream display an error and stop play back.
|
// the stream display an error and stop play back.
|
||||||
|
@ -275,7 +288,14 @@
|
||||||
} else {
|
} else {
|
||||||
var artist = data.current.name.split(" - ")[0];
|
var artist = data.current.name.split(" - ")[0];
|
||||||
var track = data.current.name.split(" - ")[1];
|
var track = data.current.name.split(" - ")[1];
|
||||||
$("p.now_playing").html(artist + "<span>" + track + "</span>");
|
var nowPlayingHtml = "";
|
||||||
|
if (artist) {
|
||||||
|
nowPlayingHtml += artist;
|
||||||
|
}
|
||||||
|
if (track) {
|
||||||
|
nowPlayingHtml += "<span>" + track + "</span>";
|
||||||
|
}
|
||||||
|
$("p.now_playing").html(nowPlayingHtml);
|
||||||
|
|
||||||
var current_track_end_time = new Date(data.current.ends);
|
var current_track_end_time = new Date(data.current.ends);
|
||||||
if (current_track_end_time == "Invalid Date" || isNaN(current_track_end_time)) {
|
if (current_track_end_time == "Invalid Date" || isNaN(current_track_end_time)) {
|
||||||
|
|
Loading…
Reference in New Issue