Skip to content

Commit dbd0894

Browse files
committed
Fix bugs in external transcript for YouTube
1 parent c5e2168 commit dbd0894

10 files changed

Lines changed: 84 additions & 29 deletions

build/ableplayer.dist.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,21 @@
189189
// 3. "popup" - Automatically generated, written to a draggable, resizable popup window that can be toggled on/off with a button
190190
// If data-include-transcript="false", there is no "popup" transcript
191191

192+
if ($(media).data('transcript-div') !== undefined && $(media).data('transcript-div') !== "") {
193+
this.transcriptDivLocation = $(media).data('transcript-div');
194+
}
195+
else {
196+
this.transcriptDivLocation = null;
197+
}
198+
if ($(media).data('include-transcript') !== undefined && $(media).data('include-transcript') === false) {
199+
200+
this.hideTranscriptButton = true;
201+
}
202+
else {
203+
204+
this.hideTranscriptButton = null;
205+
}
206+
192207
this.transcriptType = null;
193208
if ($(media).data('transcript-src') !== undefined) {
194209
this.transcriptSrc = $(media).data('transcript-src');
@@ -198,20 +213,18 @@
198213
}
199214
else if ($(media).find('track[kind="captions"], track[kind="subtitles"]').length > 0) {
200215
// required tracks are present. COULD automatically generate a transcript
201-
if ($(media).data('transcript-div') !== undefined && $(media).data('transcript-div') !== "") {
202-
this.transcriptDivLocation = $(media).data('transcript-div');
216+
if (this.transcriptDivLocation) {
203217
this.transcriptType = 'external';
204218
}
205-
else if ($(media).data('include-transcript') !== undefined) {
206-
if ($(media).data('include-transcript') !== false) {
207-
this.transcriptType = 'popup';
208-
}
209-
}
210219
else {
211220
this.transcriptType = 'popup';
212221
}
213222
}
214223

224+
225+
226+
227+
215228
// In "Lyrics Mode", line breaks in WebVTT caption files are supported in the transcript
216229
// If false (default), line breaks are are removed from transcripts in order to provide a more seamless reading experience
217230
// If true, line breaks are preserved, so content can be presented karaoke-style, or as lines in a poem
@@ -3873,7 +3886,7 @@
38733886
bll.push('descriptions'); //audio description
38743887
}
38753888
}
3876-
if (this.transcriptType === 'popup') {
3889+
if (this.transcriptType === 'popup' && !(this.hideTranscriptButton)) {
38773890
bll.push('transcript');
38783891
}
38793892

@@ -10278,7 +10291,12 @@ if (thisObj.useTtml && (trackSrc.endsWith('.xml') || trackText.startsWith('<?xml
1027810291
if (!this.transcriptType) {
1027910292
// previously set transcriptType to null since there are no <track> elements
1028010293
// check again to see if captions have been collected from other sources (e.g., YouTube)
10294+
10295+
10296+
10297+
1028110298
if (this.captions.length && (!(this.usingYouTubeCaptions || this.usingVimeoCaptions))) {
10299+
1028210300
// captions are possible! Use the default type (popup)
1028310301
// if other types ('external' and 'manual') were desired, transcriptType would not be null here
1028410302
this.transcriptType = 'popup';

build/ableplayer.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,21 @@
189189
// 3. "popup" - Automatically generated, written to a draggable, resizable popup window that can be toggled on/off with a button
190190
// If data-include-transcript="false", there is no "popup" transcript
191191

192+
if ($(media).data('transcript-div') !== undefined && $(media).data('transcript-div') !== "") {
193+
this.transcriptDivLocation = $(media).data('transcript-div');
194+
}
195+
else {
196+
this.transcriptDivLocation = null;
197+
}
198+
if ($(media).data('include-transcript') !== undefined && $(media).data('include-transcript') === false) {
199+
console.log('YOU WANT TO HIDE TRANSCRIPT BUTTON');
200+
this.hideTranscriptButton = true;
201+
}
202+
else {
203+
console.log('YOU DO NOT WANT TO HIDE TRANSCRIPT BUTTON');
204+
this.hideTranscriptButton = null;
205+
}
206+
192207
this.transcriptType = null;
193208
if ($(media).data('transcript-src') !== undefined) {
194209
this.transcriptSrc = $(media).data('transcript-src');
@@ -198,19 +213,17 @@
198213
}
199214
else if ($(media).find('track[kind="captions"], track[kind="subtitles"]').length > 0) {
200215
// required tracks are present. COULD automatically generate a transcript
201-
if ($(media).data('transcript-div') !== undefined && $(media).data('transcript-div') !== "") {
202-
this.transcriptDivLocation = $(media).data('transcript-div');
216+
if (this.transcriptDivLocation) {
203217
this.transcriptType = 'external';
204218
}
205-
else if ($(media).data('include-transcript') !== undefined) {
206-
if ($(media).data('include-transcript') !== false) {
207-
this.transcriptType = 'popup';
208-
}
209-
}
210219
else {
211220
this.transcriptType = 'popup';
212221
}
213222
}
223+
console.log('transcriptType: ' + this.transcriptType);
224+
console.log('transcriptDivLocation: ' + this.transcriptDivLocation);
225+
console.log('hideTranscriptButton: ' + this.hideTranscriptButton);
226+
214227

215228
// In "Lyrics Mode", line breaks in WebVTT caption files are supported in the transcript
216229
// If false (default), line breaks are are removed from transcripts in order to provide a more seamless reading experience
@@ -3873,7 +3886,7 @@
38733886
bll.push('descriptions'); //audio description
38743887
}
38753888
}
3876-
if (this.transcriptType === 'popup') {
3889+
if (this.transcriptType === 'popup' && !(this.hideTranscriptButton)) {
38773890
bll.push('transcript');
38783891
}
38793892

@@ -10278,7 +10291,12 @@ if (thisObj.useTtml && (trackSrc.endsWith('.xml') || trackText.startsWith('<?xml
1027810291
if (!this.transcriptType) {
1027910292
// previously set transcriptType to null since there are no <track> elements
1028010293
// check again to see if captions have been collected from other sources (e.g., YouTube)
10294+
console.log("there is no transcriptType yet");
10295+
console.log('captions length: ' + this.captions.length);
10296+
console.log('usingYouTubeCaptions: ' + this.usingYouTubeCaptions);
10297+
1028110298
if (this.captions.length && (!(this.usingYouTubeCaptions || this.usingVimeoCaptions))) {
10299+
console.log('captions are possible!');
1028210300
// captions are possible! Use the default type (popup)
1028310301
// if other types ('external' and 'manual') were desired, transcriptType would not be null here
1028410302
this.transcriptType = 'popup';

build/ableplayer.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/ableplayer.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demos/youtube2.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ <h1>Able Player for YouTube (Complex Example)</h1>
7070
data-transcript-div="transcript"
7171
data-chapters-div="chapters"
7272
data-use-chapters-button="false"
73+
data-include-transcript="false"
7374
playsinline
7475
>
7576
<track kind="chapters" src="../media/itaccess_chapters_en.vtt" srclang="en" label="Speakers"/>

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ableplayer",
3-
"version": "4.0.03",
3+
"version": "4.0.04",
44
"description": "fully accessible HTML5 media player",
55
"homepage": "http://ableplayer.github.io/ableplayer",
66
"bugs": "https://github.com/ableplayer/ableplayer/issues",

scripts/ableplayer-base.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,21 @@
189189
// 3. "popup" - Automatically generated, written to a draggable, resizable popup window that can be toggled on/off with a button
190190
// If data-include-transcript="false", there is no "popup" transcript
191191

192+
if ($(media).data('transcript-div') !== undefined && $(media).data('transcript-div') !== "") {
193+
this.transcriptDivLocation = $(media).data('transcript-div');
194+
}
195+
else {
196+
this.transcriptDivLocation = null;
197+
}
198+
if ($(media).data('include-transcript') !== undefined && $(media).data('include-transcript') === false) {
199+
console.log('YOU WANT TO HIDE TRANSCRIPT BUTTON');
200+
this.hideTranscriptButton = true;
201+
}
202+
else {
203+
console.log('YOU DO NOT WANT TO HIDE TRANSCRIPT BUTTON');
204+
this.hideTranscriptButton = null;
205+
}
206+
192207
this.transcriptType = null;
193208
if ($(media).data('transcript-src') !== undefined) {
194209
this.transcriptSrc = $(media).data('transcript-src');
@@ -198,19 +213,17 @@
198213
}
199214
else if ($(media).find('track[kind="captions"], track[kind="subtitles"]').length > 0) {
200215
// required tracks are present. COULD automatically generate a transcript
201-
if ($(media).data('transcript-div') !== undefined && $(media).data('transcript-div') !== "") {
202-
this.transcriptDivLocation = $(media).data('transcript-div');
216+
if (this.transcriptDivLocation) {
203217
this.transcriptType = 'external';
204218
}
205-
else if ($(media).data('include-transcript') !== undefined) {
206-
if ($(media).data('include-transcript') !== false) {
207-
this.transcriptType = 'popup';
208-
}
209-
}
210219
else {
211220
this.transcriptType = 'popup';
212221
}
213222
}
223+
console.log('transcriptType: ' + this.transcriptType);
224+
console.log('transcriptDivLocation: ' + this.transcriptDivLocation);
225+
console.log('hideTranscriptButton: ' + this.hideTranscriptButton);
226+
214227

215228
// In "Lyrics Mode", line breaks in WebVTT caption files are supported in the transcript
216229
// If false (default), line breaks are are removed from transcripts in order to provide a more seamless reading experience

scripts/buildplayer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@
840840
bll.push('descriptions'); //audio description
841841
}
842842
}
843-
if (this.transcriptType === 'popup') {
843+
if (this.transcriptType === 'popup' && !(this.hideTranscriptButton)) {
844844
bll.push('transcript');
845845
}
846846

scripts/transcript.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
if (!this.transcriptType) {
99
// previously set transcriptType to null since there are no <track> elements
1010
// check again to see if captions have been collected from other sources (e.g., YouTube)
11+
console.log("there is no transcriptType yet");
12+
console.log('captions length: ' + this.captions.length);
13+
console.log('usingYouTubeCaptions: ' + this.usingYouTubeCaptions);
14+
1115
if (this.captions.length && (!(this.usingYouTubeCaptions || this.usingVimeoCaptions))) {
16+
console.log('captions are possible!');
1217
// captions are possible! Use the default type (popup)
1318
// if other types ('external' and 'manual') were desired, transcriptType would not be null here
1419
this.transcriptType = 'popup';

0 commit comments

Comments
 (0)