Skip to content

Commit c1e809a

Browse files
committed
Replace non-localized error messages with ultimate fallback
1 parent ea3767c commit c1e809a

17 files changed

Lines changed: 106 additions & 81 deletions

build/ableplayer.dist.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868
this.media = media;
6969
if ($(media).length === 0) {
70-
this.provideFallback('ERROR: No media specified.');
70+
this.provideFallback();
7171
return;
7272
}
7373

@@ -441,7 +441,7 @@
441441
}
442442
else {
443443
// can't continue loading player with no text
444-
thisObj.provideFallback('ERROR: Failed to load translation table');
444+
thisObj.provideFallback();
445445
}
446446
}
447447
);
@@ -455,7 +455,7 @@
455455
this.reinitialize().then(function () {
456456
if (!thisObj.player) {
457457
// No player for this media, show last-line fallback.
458-
thisObj.provideFallback('Unable to play media');
458+
thisObj.provideFallback();
459459
}
460460
else {
461461
thisObj.setupInstance().then(function () {
@@ -803,10 +803,8 @@
803803
this.mediaType = 'video';
804804
}
805805
else {
806-
this.mediaType = this.$media.get(0).tagName;
807-
errorMsg = 'Media player initialized with ' + this.mediaType + '#' + this.mediaId + '. ';
808-
errorMsg += 'Expecting an HTML5 audio or video element.';
809-
this.provideFallback(errorMsg);
806+
// Able Player was initialized with some element other than <video> or <audio>
807+
this.provideFallback();
810808
deferred.fail();
811809
return promise;
812810
}
@@ -816,7 +814,7 @@
816814
this.player = this.getPlayer();
817815
if (!this.player) {
818816
// an error was generated in getPlayer()
819-
this.provideFallback(this.error);
817+
this.provideFallback();
820818
}
821819
this.setIconType();
822820
this.setDimensions();
@@ -1068,7 +1066,7 @@
10681066
thisObj.showSearchResults();
10691067
},
10701068
function() { // initPlayer fail
1071-
thisObj.provideFallback(this.error);
1069+
thisObj.provideFallback();
10721070
}
10731071
);
10741072
});
@@ -1292,7 +1290,6 @@
12921290
},
12931291
error: function(jqXHR, textStatus, errorThrown) {
12941292
// Loading the JW Player failed
1295-
this.error = 'Failed to load JW Player.';
12961293
deferred.reject();
12971294
}
12981295
});
@@ -1327,7 +1324,7 @@
13271324
var i, sourceType, $newItem;
13281325
if (this.youTubeId) {
13291326
if (this.mediaType !== 'video') {
1330-
this.error = 'To play a YouTube video, use the &lt;video&gt; tag.';
1327+
// attempting to play a YouTube video using an element other than <video>
13311328
return null;
13321329
}
13331330
else {
@@ -1341,19 +1338,25 @@
13411338
// the user wants to test the fallback player, or
13421339
// the user is using an older version of IE or IOS,
13431340
// both of which had buggy implementation of HTML5 video
1344-
if (this.fallback === 'jw' && this.jwCanPlay()) {
1345-
return 'jw';
1341+
if (this.fallback === 'jw') {
1342+
if (this.jwCanPlay()) {
1343+
return 'jw';
1344+
}
1345+
else {
1346+
// JW Player is available as fallback, but can't play this source file
1347+
return null;
1348+
}
13461349
}
13471350
else {
1348-
this.error = 'The fallback player (JW Player) is unable to play the available media file.';
1351+
// browser doesn't support HTML5 video and there is no fallback player
13491352
return null;
13501353
}
13511354
}
13521355
else if (this.media.canPlayType) {
13531356
return 'html5';
13541357
}
13551358
else {
1356-
this.error = 'This browser does not support the available media file.';
1359+
// Browser does not support the available media file
13571360
return null;
13581361
}
13591362
};
@@ -3803,11 +3806,11 @@
38033806
}
38043807
};
38053808

3806-
AblePlayer.prototype.provideFallback = function(reason) {
3809+
AblePlayer.prototype.provideFallback = function() {
38073810

38083811
// provide ultimate fallback for users who are unable to play the media
3809-
// reason is a specific error message
3810-
// if reason is 'NO SUPPORT', use standard text from translation file
3812+
// If there is HTML content nested within the media element, display that
3813+
// Otherwise, display standard localized error text
38113814

38123815
var $fallbackDiv, width, mediaClone, fallback, fallbackText,
38133816
showBrowserList, browsers, i, b, browserList;
@@ -3839,18 +3842,14 @@
38393842
if (fallback.length) {
38403843
$fallbackDiv.html(fallback);
38413844
}
3842-
else if (reason == 'NO SUPPORT') {
3843-
// not using a supporting browser; use standard text from translation file
3845+
else {
3846+
// use standard localized error message
38443847
fallbackText = this.tt.fallbackError1 + ' ' + this.tt[this.mediaType] + '. ';
38453848
fallbackText += this.tt.fallbackError2 + ':';
38463849
fallback = $('<p>').text(fallbackText);
38473850
$fallbackDiv.html(fallback);
38483851
showBrowserList = true;
38493852
}
3850-
else {
3851-
// show the reason
3852-
$fallbackDiv.text(reason);
3853-
}
38543853

38553854
if (showBrowserList) {
38563855
browserList = $('<ul>');

build/ableplayer.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868
this.media = media;
6969
if ($(media).length === 0) {
70-
this.provideFallback('ERROR: No media specified.');
70+
this.provideFallback();
7171
return;
7272
}
7373

@@ -441,7 +441,7 @@
441441
}
442442
else {
443443
// can't continue loading player with no text
444-
thisObj.provideFallback('ERROR: Failed to load translation table');
444+
thisObj.provideFallback();
445445
}
446446
}
447447
);
@@ -455,7 +455,7 @@
455455
this.reinitialize().then(function () {
456456
if (!thisObj.player) {
457457
// No player for this media, show last-line fallback.
458-
thisObj.provideFallback('Unable to play media');
458+
thisObj.provideFallback();
459459
}
460460
else {
461461
thisObj.setupInstance().then(function () {
@@ -803,10 +803,8 @@
803803
this.mediaType = 'video';
804804
}
805805
else {
806-
this.mediaType = this.$media.get(0).tagName;
807-
errorMsg = 'Media player initialized with ' + this.mediaType + '#' + this.mediaId + '. ';
808-
errorMsg += 'Expecting an HTML5 audio or video element.';
809-
this.provideFallback(errorMsg);
806+
// Able Player was initialized with some element other than <video> or <audio>
807+
this.provideFallback();
810808
deferred.fail();
811809
return promise;
812810
}
@@ -816,7 +814,7 @@
816814
this.player = this.getPlayer();
817815
if (!this.player) {
818816
// an error was generated in getPlayer()
819-
this.provideFallback(this.error);
817+
this.provideFallback();
820818
}
821819
this.setIconType();
822820
this.setDimensions();
@@ -1068,7 +1066,7 @@
10681066
thisObj.showSearchResults();
10691067
},
10701068
function() { // initPlayer fail
1071-
thisObj.provideFallback(this.error);
1069+
thisObj.provideFallback();
10721070
}
10731071
);
10741072
});
@@ -1292,7 +1290,6 @@
12921290
},
12931291
error: function(jqXHR, textStatus, errorThrown) {
12941292
// Loading the JW Player failed
1295-
this.error = 'Failed to load JW Player.';
12961293
deferred.reject();
12971294
}
12981295
});
@@ -1327,7 +1324,7 @@
13271324
var i, sourceType, $newItem;
13281325
if (this.youTubeId) {
13291326
if (this.mediaType !== 'video') {
1330-
this.error = 'To play a YouTube video, use the &lt;video&gt; tag.';
1327+
// attempting to play a YouTube video using an element other than <video>
13311328
return null;
13321329
}
13331330
else {
@@ -1341,19 +1338,25 @@
13411338
// the user wants to test the fallback player, or
13421339
// the user is using an older version of IE or IOS,
13431340
// both of which had buggy implementation of HTML5 video
1344-
if (this.fallback === 'jw' && this.jwCanPlay()) {
1345-
return 'jw';
1341+
if (this.fallback === 'jw') {
1342+
if (this.jwCanPlay()) {
1343+
return 'jw';
1344+
}
1345+
else {
1346+
// JW Player is available as fallback, but can't play this source file
1347+
return null;
1348+
}
13461349
}
13471350
else {
1348-
this.error = 'The fallback player (JW Player) is unable to play the available media file.';
1351+
// browser doesn't support HTML5 video and there is no fallback player
13491352
return null;
13501353
}
13511354
}
13521355
else if (this.media.canPlayType) {
13531356
return 'html5';
13541357
}
13551358
else {
1356-
this.error = 'This browser does not support the available media file.';
1359+
// Browser does not support the available media file
13571360
return null;
13581361
}
13591362
};
@@ -3803,11 +3806,11 @@
38033806
}
38043807
};
38053808

3806-
AblePlayer.prototype.provideFallback = function(reason) {
3809+
AblePlayer.prototype.provideFallback = function() {
38073810

38083811
// provide ultimate fallback for users who are unable to play the media
3809-
// reason is a specific error message
3810-
// if reason is 'NO SUPPORT', use standard text from translation file
3812+
// If there is HTML content nested within the media element, display that
3813+
// Otherwise, display standard localized error text
38113814

38123815
var $fallbackDiv, width, mediaClone, fallback, fallbackText,
38133816
showBrowserList, browsers, i, b, browserList;
@@ -3839,18 +3842,14 @@
38393842
if (fallback.length) {
38403843
$fallbackDiv.html(fallback);
38413844
}
3842-
else if (reason == 'NO SUPPORT') {
3843-
// not using a supporting browser; use standard text from translation file
3845+
else {
3846+
// use standard localized error message
38443847
fallbackText = this.tt.fallbackError1 + ' ' + this.tt[this.mediaType] + '. ';
38453848
fallbackText += this.tt.fallbackError2 + ':';
38463849
fallback = $('<p>').text(fallbackText);
38473850
$fallbackDiv.html(fallback);
38483851
showBrowserList = true;
38493852
}
3850-
else {
3851-
// show the reason
3852-
$fallbackDiv.text(reason);
3853-
}
38543853

38553854
if (showBrowserList) {
38563855
browserList = $('<ul>');

0 commit comments

Comments
 (0)