Skip to content

Commit a74f952

Browse files
committed
Fix bug in support for default attribute on tracks
1 parent 8da3b9a commit a74f952

11 files changed

Lines changed: 168 additions & 39 deletions

build/ableplayer.dist.js

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,13 @@
557557
this.setupTracks().then(function () {
558558
thisObj.setupPopups();
559559
thisObj.initDescription();
560+
thisObj.updateDescription();
560561
thisObj.initializing = false;
561562
thisObj.initPlayer();
563+
thisObj.initDefaultCaption();
564+
thisObj.updateCaption();
565+
thisObj.updateTranscript();
566+
thisObj.showSearchResults();
562567
});
563568
};
564569

@@ -591,12 +596,14 @@
591596
thisObj.setFullscreen(false);
592597
thisObj.setVolume(thisObj.defaultVolume);
593598
thisObj.initializing = true;
594-
// If using open description (as determined previously based on prefs & availability)
595-
// swap media file now
599+
// Moved this block to recreatePlayer()
600+
// Preserved here to ensure there are no problems
601+
/*
596602
thisObj.updateDescription();
597603
thisObj.updateCaption();
598604
thisObj.updateTranscript();
599605
thisObj.showSearchResults();
606+
*/
600607
thisObj.initializing = false;
601608
thisObj.refreshControls();
602609

@@ -622,6 +629,32 @@
622629

623630
return promise;
624631
};
632+
633+
AblePlayer.prototype.initDefaultCaption = function () {
634+
var i;
635+
if (this.captions.length > 0) {
636+
for (i=0; i<this.captions.length; i++) {
637+
if (this.captions[i].def === true) {
638+
this.captionLang = this.captions[i].language;
639+
this.selectedCaptions = this.captions[i];
640+
}
641+
}
642+
}
643+
if (typeof this.captionLang === 'undefined') {
644+
// find and use a caption language that matches the player language
645+
for (i=0; i<this.captions.length; i++) {
646+
if (this.captions[i].language === this.lang) {
647+
this.captionLang = this.captions[i].language;
648+
this.selectedCaptions = this.captions[i];
649+
}
650+
}
651+
}
652+
if (typeof this.captionLang === 'undefined') {
653+
// just use the first track
654+
this.captionLang = this.captions[0].language;
655+
this.selectedCaptions = this.captions[0];
656+
}
657+
};
625658

626659
AblePlayer.prototype.initHtml5Player = function () {
627660
// Nothing special to do!
@@ -2230,7 +2263,7 @@
22302263
thisObj.scrollingTranscript = false;
22312264
});
22322265

2233-
this.$transcriptLanguageSelect.change(function () {
2266+
this.$transcriptLanguageSelect.change(function () {
22342267
var language = thisObj.$transcriptLanguageSelect.val();
22352268
for (var ii in thisObj.captions) {
22362269
if (thisObj.captions[ii].language === language) {
@@ -3204,6 +3237,7 @@
32043237
var track = this.$tracks[ii];
32053238
var kind = track.getAttribute('kind');
32063239
var trackSrc = track.getAttribute('src');
3240+
var isDefaultTrack = track.getAttribute('default');
32073241

32083242
if (!trackSrc) {
32093243
// Nothing to load!
@@ -3231,7 +3265,7 @@
32313265
}
32323266
})(track, kind));
32333267
}
3234-
3268+
32353269
$.when.apply($, loadingPromises).then(function () {
32363270
deferred.resolve();
32373271
});
@@ -3256,7 +3290,6 @@
32563290
else {
32573291
var isDefaultTrack = false;
32583292
}
3259-
32603293
// caption cues from WebVTT are used to build a transcript for both audio and video
32613294
// but captions are currently only supported for video
32623295
if (this.mediaType === 'video') {
@@ -4971,6 +5004,14 @@
49715004
// captions are off. Turn them on.
49725005
this.captionsOn = true;
49735006
this.$captionDiv.show();
5007+
5008+
5009+
5010+
for (var i=0; i<this.captions.length; i++) {
5011+
if (this.captions[i].def === true) { // this is the default language
5012+
this.selectedCaptions = this.captions[i];
5013+
}
5014+
}
49745015
this.selectedCaptions = this.captions[0];
49755016
if (this.descriptions.length >= 0) {
49765017
this.selectedDescriptions = this.descriptions[0];
@@ -5277,7 +5318,7 @@
52775318
})(jQuery);
52785319

52795320
(function ($) {
5280-
AblePlayer.prototype.updateCaption = function (time) {
5321+
AblePlayer.prototype.updateCaption = function (time) {
52815322
if (this.captionsOn) {
52825323
this.$captionDiv.show();
52835324
this.showCaptions(time || this.getElapsed());
@@ -5293,6 +5334,7 @@
52935334
return function () {
52945335
thisObj.captionsOn = true;
52955336
thisObj.selectedCaptions = track;
5337+
thisObj.captionLang = track.language;
52965338
thisObj.currentCaption = -1;
52975339
// Try and find a matching description track.
52985340
for (var ii in thisObj.descriptions) {
@@ -5325,7 +5367,6 @@
53255367

53265368
AblePlayer.prototype.showCaptions = function(now) {
53275369
var c, thisCaption;
5328-
53295370
var cues;
53305371
if (this.selectedCaptions) {
53315372
cues = this.selectedCaptions.cues;
@@ -5530,13 +5571,15 @@
55305571
var captions;
55315572
var descriptions;
55325573
var captionLang;
5533-
if (this.transcriptCaptions) {
5574+
if (this.transcriptCaptions) {
5575+
// use this independently of this.selectedCaptions
5576+
// user might want captions in one language, transcript in another
55345577
captionLang = this.transcriptCaptions.language;
55355578
captions = this.transcriptCaptions.cues;
55365579
}
5537-
else if (this.captions.length > 0) {
5538-
captionLang = this.captions[0].language;
5539-
captions = this.captions[0].cues;
5580+
else if (this.selectedCaptions) {
5581+
captionLang = this.captionLang;
5582+
captions = this.selectedCaptions.cues;
55405583
}
55415584
if (this.transcriptDescriptions) {
55425585
descriptions = this.transcriptDescriptions.cues;

build/ableplayer.js

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,13 @@
557557
this.setupTracks().then(function () {
558558
thisObj.setupPopups();
559559
thisObj.initDescription();
560+
thisObj.updateDescription();
560561
thisObj.initializing = false;
561562
thisObj.initPlayer();
563+
thisObj.initDefaultCaption();
564+
thisObj.updateCaption();
565+
thisObj.updateTranscript();
566+
thisObj.showSearchResults();
562567
});
563568
};
564569

@@ -591,12 +596,14 @@
591596
thisObj.setFullscreen(false);
592597
thisObj.setVolume(thisObj.defaultVolume);
593598
thisObj.initializing = true;
594-
// If using open description (as determined previously based on prefs & availability)
595-
// swap media file now
599+
// Moved this block to recreatePlayer()
600+
// Preserved here to ensure there are no problems
601+
/*
596602
thisObj.updateDescription();
597603
thisObj.updateCaption();
598604
thisObj.updateTranscript();
599605
thisObj.showSearchResults();
606+
*/
600607
thisObj.initializing = false;
601608
thisObj.refreshControls();
602609

@@ -622,6 +629,32 @@
622629

623630
return promise;
624631
};
632+
633+
AblePlayer.prototype.initDefaultCaption = function () {
634+
var i;
635+
if (this.captions.length > 0) {
636+
for (i=0; i<this.captions.length; i++) {
637+
if (this.captions[i].def === true) {
638+
this.captionLang = this.captions[i].language;
639+
this.selectedCaptions = this.captions[i];
640+
}
641+
}
642+
}
643+
if (typeof this.captionLang === 'undefined') {
644+
// find and use a caption language that matches the player language
645+
for (i=0; i<this.captions.length; i++) {
646+
if (this.captions[i].language === this.lang) {
647+
this.captionLang = this.captions[i].language;
648+
this.selectedCaptions = this.captions[i];
649+
}
650+
}
651+
}
652+
if (typeof this.captionLang === 'undefined') {
653+
// just use the first track
654+
this.captionLang = this.captions[0].language;
655+
this.selectedCaptions = this.captions[0];
656+
}
657+
};
625658

626659
AblePlayer.prototype.initHtml5Player = function () {
627660
// Nothing special to do!
@@ -2230,7 +2263,7 @@
22302263
thisObj.scrollingTranscript = false;
22312264
});
22322265

2233-
this.$transcriptLanguageSelect.change(function () {
2266+
this.$transcriptLanguageSelect.change(function () {
22342267
var language = thisObj.$transcriptLanguageSelect.val();
22352268
for (var ii in thisObj.captions) {
22362269
if (thisObj.captions[ii].language === language) {
@@ -3204,6 +3237,7 @@ console.log('handling keydown on popup');
32043237
var track = this.$tracks[ii];
32053238
var kind = track.getAttribute('kind');
32063239
var trackSrc = track.getAttribute('src');
3240+
var isDefaultTrack = track.getAttribute('default');
32073241

32083242
if (!trackSrc) {
32093243
// Nothing to load!
@@ -3231,7 +3265,7 @@ console.log('handling keydown on popup');
32313265
}
32323266
})(track, kind));
32333267
}
3234-
3268+
32353269
$.when.apply($, loadingPromises).then(function () {
32363270
deferred.resolve();
32373271
});
@@ -3256,7 +3290,6 @@ console.log('handling keydown on popup');
32563290
else {
32573291
var isDefaultTrack = false;
32583292
}
3259-
32603293
// caption cues from WebVTT are used to build a transcript for both audio and video
32613294
// but captions are currently only supported for video
32623295
if (this.mediaType === 'video') {
@@ -4971,6 +5004,14 @@ console.log('handling keydown on popup');
49715004
// captions are off. Turn them on.
49725005
this.captionsOn = true;
49735006
this.$captionDiv.show();
5007+
console.log('SelectedCaptions:');
5008+
console.log(typeof this.selectedCaptions);
5009+
console.log(this.selectedCaptions);
5010+
for (var i=0; i<this.captions.length; i++) {
5011+
if (this.captions[i].def === true) { // this is the default language
5012+
this.selectedCaptions = this.captions[i];
5013+
}
5014+
}
49745015
this.selectedCaptions = this.captions[0];
49755016
if (this.descriptions.length >= 0) {
49765017
this.selectedDescriptions = this.descriptions[0];
@@ -5277,7 +5318,7 @@ console.log('handling keydown on popup');
52775318
})(jQuery);
52785319

52795320
(function ($) {
5280-
AblePlayer.prototype.updateCaption = function (time) {
5321+
AblePlayer.prototype.updateCaption = function (time) {
52815322
if (this.captionsOn) {
52825323
this.$captionDiv.show();
52835324
this.showCaptions(time || this.getElapsed());
@@ -5293,6 +5334,7 @@ console.log('handling keydown on popup');
52935334
return function () {
52945335
thisObj.captionsOn = true;
52955336
thisObj.selectedCaptions = track;
5337+
thisObj.captionLang = track.language;
52965338
thisObj.currentCaption = -1;
52975339
// Try and find a matching description track.
52985340
for (var ii in thisObj.descriptions) {
@@ -5325,7 +5367,6 @@ console.log('handling keydown on popup');
53255367

53265368
AblePlayer.prototype.showCaptions = function(now) {
53275369
var c, thisCaption;
5328-
53295370
var cues;
53305371
if (this.selectedCaptions) {
53315372
cues = this.selectedCaptions.cues;
@@ -5530,13 +5571,15 @@ console.log('handling keydown on popup');
55305571
var captions;
55315572
var descriptions;
55325573
var captionLang;
5533-
if (this.transcriptCaptions) {
5574+
if (this.transcriptCaptions) {
5575+
// use this independently of this.selectedCaptions
5576+
// user might want captions in one language, transcript in another
55345577
captionLang = this.transcriptCaptions.language;
55355578
captions = this.transcriptCaptions.cues;
55365579
}
5537-
else if (this.captions.length > 0) {
5538-
captionLang = this.captions[0].language;
5539-
captions = this.captions[0].cues;
5580+
else if (this.selectedCaptions) {
5581+
captionLang = this.captionLang;
5582+
captions = this.selectedCaptions.cues;
55405583
}
55415584
if (this.transcriptDescriptions) {
55425585
descriptions = this.transcriptDescriptions.cues;

0 commit comments

Comments
 (0)