Skip to content

Commit ac2dc11

Browse files
committed
Merge PR from jessehall3
1 parent a0f8843 commit ac2dc11

8 files changed

Lines changed: 119 additions & 17 deletions

File tree

build/ableplayer.js

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3396,10 +3396,20 @@
33963396
tracks = this.captions;
33973397
}
33983398
else if (popup == 'chapters') {
3399-
if (typeof this.chaptersPopup === 'undefined') {
3400-
this.chaptersPopup = this.createPopup('chapters');
3401-
}
3402-
tracks = this.chapters;
3399+
// sets the appropriate language for chapters if there are multiple chapter tracks available.
3400+
thisObj.updateChaptersLanguage();
3401+
if (typeof this.chaptersPopup === 'undefined') {
3402+
this.chaptersPopup = this.createPopup('chapters');
3403+
}
3404+
if (this.selectedChapters) {
3405+
tracks = this.selectedChapters.cues;
3406+
}
3407+
else if (this.chapters.length >= 1) {
3408+
tracks = this.chapters[0].cues;
3409+
}
3410+
else {
3411+
tracks = [];
3412+
}
34033413
}
34043414
else if (popup == 'ytCaptions') {
34053415
if (typeof this.captionsPopup === 'undefined') {
@@ -4693,14 +4703,13 @@
46934703
// Replace the following line with the commented block that follows
46944704
// Haven't done this because it will have a big effect downstream
46954705
// on all chapter processing
4696-
this.chapters = cues;
4706+
//this.chapters = cues;
46974707

4698-
/* // new
4708+
// new
46994709
this.chapters.push({
47004710
cues: cues,
47014711
language: trackLang
47024712
});
4703-
*/
47044713

47054714
if (this.chaptersDivLocation) {
47064715
this.populateChaptersDiv();
@@ -7308,6 +7317,10 @@
73087317
else if (this.player === 'youtube') {
73097318
this.seekBar.setBuffered(this.youTubePlayer.getVideoLoadedFraction());
73107319
}
7320+
// This will adjust the text in the chapter pop-ups.
7321+
// This is to respond to changes in the caption language and transcript language when appropriate.
7322+
// See "updateChaptersLanguage" in chapters.js to see how this is handled.
7323+
this.setupPopups('chapters');
73117324
};
73127325

73137326
AblePlayer.prototype.getHiddenWidth = function($el) {
@@ -7632,6 +7645,7 @@
76327645
this.prefTranscript = 1;
76337646
}
76347647
this.updateCookie('prefTranscript');
7648+
this.setupPopups('chapters');
76357649
};
76367650

76377651
AblePlayer.prototype.handleSignToggle = function () {
@@ -8617,6 +8631,37 @@
86178631
}
86188632
};
86198633

8634+
AblePlayer.prototype.updateChaptersLanguage = function () {
8635+
var thisObj = this;
8636+
var matchChapLang = function (languageToMatch){
8637+
for (var i = 0; i < thisObj.chapters.length; i++) {
8638+
if(languageToMatch == thisObj.chapters[i].language){
8639+
thisObj.selectedChapters = thisObj.chapters[i];
8640+
return true;
8641+
}
8642+
}
8643+
return false;
8644+
};
8645+
8646+
var isSelectedChaptersUpdated = false;
8647+
// if captions are on, use the language of the captions
8648+
if(this.captionsOn || this.prefCaptions){
8649+
isSelectedChaptersUpdated = matchChapLang(this.captionLang);
8650+
}
8651+
// if captions are off, and the transcript is on, use the transcript language
8652+
if(this.prefTranscript && !(isSelectedChaptersUpdated)){
8653+
isSelectedChaptersUpdated = matchChapLang(this.$transcriptLanguageSelect.val());
8654+
}
8655+
// if none of the above, use the language of the player
8656+
if(!(isSelectedChaptersUpdated)){
8657+
isSelectedChaptersUpdated = matchChapLang(this.lang);
8658+
}
8659+
// if can't match any of that, use the first track in the Chapters array
8660+
if(!(isSelectedChaptersUpdated) && (this.chapters.length >= 1)) {
8661+
this.selectedChapters = (this.chapters[0]);
8662+
}
8663+
};
8664+
86208665
})(jQuery);
86218666

86228667
(function ($) {
@@ -8841,6 +8886,7 @@
88418886
}
88428887
}
88438888
thisObj.updateTranscript();
8889+
thisObj.setupPopups('chapters');
88448890
});
88458891
}
88468892
};
@@ -8916,7 +8962,7 @@
89168962
}
89178963
}
89188964
if (typeof chapters === 'undefined') {
8919-
chapters = this.chapters;
8965+
chapters = this.chapters[0] || [];
89208966
}
89218967
}
89228968

demos/local_es.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ <h1>Able Player en Español</h1>
3131
<track kind="captions" src="../media/wwa_captions_es.vtt" srclang="es" label="Espanol" default/>
3232
<track kind="descriptions" src="../media/wwa_description_en.vtt" srclang="en"/>
3333
<track kind="descriptions" src="../media/wwa_description_es.vtt" srclang="es"/>
34-
<track kind="chapters" src="../media/wwa_chapters_en.vtt"/>
34+
<track kind="chapters" src="../media/wwa_chapters_en.vtt" srclang="en"/>
35+
<track kind="chapters" src="../media/wwa_chapters_es.vtt" srclang="es"/>
3536
</video>
3637

3738
</body>

media/wwa_chapters_es.vtt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
WEBVTT
2+
3+
Chapter 1
4+
00:00:00.000 --> 00:00:37.000
5+
Introducción
6+
7+
Chapter 2
8+
00:00:37.000 --> 00:01:00.000
9+
Terrill Thompson

scripts/buildplayer.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,20 @@
596596
tracks = this.captions;
597597
}
598598
else if (popup == 'chapters') {
599-
if (typeof this.chaptersPopup === 'undefined') {
600-
this.chaptersPopup = this.createPopup('chapters');
601-
}
602-
tracks = this.chapters;
599+
// sets the appropriate language for chapters if there are multiple chapter tracks available.
600+
thisObj.updateChaptersLanguage();
601+
if (typeof this.chaptersPopup === 'undefined') {
602+
this.chaptersPopup = this.createPopup('chapters');
603+
}
604+
if (this.selectedChapters) {
605+
tracks = this.selectedChapters.cues;
606+
}
607+
else if (this.chapters.length >= 1) {
608+
tracks = this.chapters[0].cues;
609+
}
610+
else {
611+
tracks = [];
612+
}
603613
}
604614
else if (popup == 'ytCaptions') {
605615
if (typeof this.captionsPopup === 'undefined') {

scripts/chapters.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,35 @@
114114
}
115115
};
116116

117+
AblePlayer.prototype.updateChaptersLanguage = function () {
118+
var thisObj = this;
119+
var matchChapLang = function (languageToMatch){
120+
for (var i = 0; i < thisObj.chapters.length; i++) {
121+
if(languageToMatch == thisObj.chapters[i].language){
122+
thisObj.selectedChapters = thisObj.chapters[i];
123+
return true;
124+
}
125+
}
126+
return false;
127+
};
128+
129+
var isSelectedChaptersUpdated = false;
130+
// if captions are on, use the language of the captions
131+
if(this.captionsOn || this.prefCaptions){
132+
isSelectedChaptersUpdated = matchChapLang(this.captionLang);
133+
}
134+
// if captions are off, and the transcript is on, use the transcript language
135+
if(this.prefTranscript && !(isSelectedChaptersUpdated)){
136+
isSelectedChaptersUpdated = matchChapLang(this.$transcriptLanguageSelect.val());
137+
}
138+
// if none of the above, use the language of the player
139+
if(!(isSelectedChaptersUpdated)){
140+
isSelectedChaptersUpdated = matchChapLang(this.lang);
141+
}
142+
// if can't match any of that, use the first track in the Chapters array
143+
if(!(isSelectedChaptersUpdated) && (this.chapters.length >= 1)) {
144+
this.selectedChapters = (this.chapters[0]);
145+
}
146+
};
147+
117148
})(jQuery);

scripts/control.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,10 @@
631631
else if (this.player === 'youtube') {
632632
this.seekBar.setBuffered(this.youTubePlayer.getVideoLoadedFraction());
633633
}
634+
// This will adjust the text in the chapter pop-ups.
635+
// This is to respond to changes in the caption language and transcript language when appropriate.
636+
// See "updateChaptersLanguage" in chapters.js to see how this is handled.
637+
this.setupPopups('chapters');
634638
};
635639

636640
AblePlayer.prototype.getHiddenWidth = function($el) {
@@ -955,6 +959,7 @@
955959
this.prefTranscript = 1;
956960
}
957961
this.updateCookie('prefTranscript');
962+
this.setupPopups('chapters');
958963
};
959964

960965
AblePlayer.prototype.handleSignToggle = function () {

scripts/track.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,13 @@
220220
// Replace the following line with the commented block that follows
221221
// Haven't done this because it will have a big effect downstream
222222
// on all chapter processing
223-
this.chapters = cues;
223+
//this.chapters = cues;
224224

225-
/* // new
225+
// new
226226
this.chapters.push({
227227
cues: cues,
228228
language: trackLang
229229
});
230-
*/
231230

232231
if (this.chaptersDivLocation) {
233232
this.populateChaptersDiv();

scripts/transcript.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
}
111111
}
112112
thisObj.updateTranscript();
113+
thisObj.setupPopups('chapters');
113114
});
114115
}
115116
};
@@ -185,7 +186,7 @@
185186
}
186187
}
187188
if (typeof chapters === 'undefined') {
188-
chapters = this.chapters;
189+
chapters = this.chapters[0] || [];
189190
}
190191
}
191192

0 commit comments

Comments
 (0)