Skip to content

Commit 0e8dcd5

Browse files
committed
Update YouTube demo & fix various YouTube bugs
1 parent c06a6ca commit 0e8dcd5

18 files changed

Lines changed: 2658 additions & 316 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ To manually code the transcript, one simple strategy is to first allow Able Play
250250
If this attribute is not provided and chapter are available, chapters will be displayed in a popup menu triggered by the Chapters button.
251251
- **data-use-chapters-button** - optional; set to "false" to exclude chapters button from controller. If using the data-chapters-div attribute to write the chapters to an external container, you might not want users to be able to toggle the chapters off.
252252
- **data-chapters-title** - optional; override default chapters title (default is "Chapters"). A null value (data-chapters-title="") eliminates the title altogether.
253-
- **data-chapters-default** - optional; identify ID of default chapter (must correspond with the text or value immediately above the timestamp in your chapter's WebVTT file. If this attribute is present, the media will be advanced to this start time. Otherwise it will start at the beginning. (See also **data-start-time**).
253+
- **data-chapters-default** - optional; identify ID of default chapter (must correspond with the text or value immediately above the timestamp in your chapter's WebVTT file). If this attribute is present, the media will be advanced to this start time. Otherwise it will start at the beginning. (See also **data-start-time**).
254254
- **data-seekbar-scope** - optional; default is "video" (seekbar represents full duration of video); if set to "chapter" seekbar represents the duration of the current chapter only
255255

256256
#### Metadata

build/ableplayer.dist.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,10 @@
22752275
cut(state, 1);
22762276
var components = act(state, getCuePayload);
22772277

2278+
if (typeof cueId === 'undefined') {
2279+
cueId = state.cues.length + 1;
2280+
}
2281+
22782282
state.cues.push({
22792283
id: cueId,
22802284
start: startTime,
@@ -2964,7 +2968,7 @@
29642968

29652969
var thisObj, headingLevel, headingType, headingId, $chaptersHeading,
29662970
$chaptersNav, $chaptersList, $chapterItem, $chapterButton,
2967-
i, itemId, chapter, buttonId, hasDefault,
2971+
i, chapter, buttonId, hasDefault,
29682972
getClickFunction, $clickedItem, $chaptersList, thisChapterIndex;
29692973

29702974
thisObj = this;
@@ -2996,7 +3000,6 @@
29963000
$chaptersList = $('<ul>');
29973001
for (i in this.chapters) {
29983002
chapter = this.chapters[i];
2999-
itemId = this.mediaId + '-chapters-' + i; // TODO: Maybe not needed???
30003003
$chapterItem = $('<li></li>');
30013004
$chapterButton = $('<button>',{
30023005
'type': 'button',
@@ -4878,6 +4881,7 @@
48784881
var playerState = thisObj.getPlayerState(x.data);
48794882
if (playerState === 'playing') {
48804883
thisObj.playing = true;
4884+
thisObj.startedPlaying = true;
48814885
}
48824886
else {
48834887
thisObj.playing = false;
@@ -5195,22 +5199,24 @@
51955199
for (var i=0; i<options.length; i++) {
51965200
if (options[i] == 'cc') { // this is the AS3 (Flash) player
51975201
this.ytCaptionModule = 'cc';
5198-
this.hasCaptions = true;
5199-
this.usingYouTubeCaptions = true;
5202+
if (!this.hasCaptions) {
5203+
// there are captions available via other sources (e.g., <track>)
5204+
// so use these
5205+
this.hasCaptions = true;
5206+
this.usingYouTubeCaptions = true;
5207+
}
52005208
break;
52015209
}
52025210
else if (options[i] == 'captions') { // this is the HTML5 player
52035211
this.ytCaptionModule = 'captions';
5204-
this.hasCaptions = true;
5205-
this.usingYouTubeCaptions = true;
5212+
if (!this.hasCaptions) {
5213+
// there are captions available via other sources (e.g., <track>)
5214+
// so use these
5215+
this.hasCaptions = true;
5216+
this.usingYouTubeCaptions = true;
5217+
}
52065218
break;
52075219
}
5208-
else {
5209-
// no recognizable caption module was found
5210-
// sorry, gonna have to disable captions if we can't control them
5211-
this.hasCaptions = false;
5212-
this.usingYouTubeCaptions = false;
5213-
}
52145220
}
52155221
if (typeof this.ytCaptionModule !== 'undefined') {
52165222
if (this.usingYouTubeCaptions) {
@@ -7491,7 +7497,6 @@
74917497
};
74927498

74937499
AblePlayer.prototype.handleChapters = function () {
7494-
74957500
if (this.hidingPopup) {
74967501
// stopgap to prevent spacebar in Firefox from reopening popup
74977502
// immediately after closing it
@@ -8879,11 +8884,13 @@
88798884
};
88808885

88818886
AblePlayer.prototype.highlightTranscript = function (currentTime) {
8887+
8888+
//show highlight in transcript marking current caption
8889+
88828890
if (!this.transcriptType) {
88838891
return;
88848892
}
88858893

8886-
//show highlight in transcript marking current caption
88878894
var start, end;
88888895
var thisObj = this;
88898896

build/ableplayer.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,10 @@
22752275
cut(state, 1);
22762276
var components = act(state, getCuePayload);
22772277

2278+
if (typeof cueId === 'undefined') {
2279+
cueId = state.cues.length + 1;
2280+
}
2281+
22782282
state.cues.push({
22792283
id: cueId,
22802284
start: startTime,
@@ -2964,7 +2968,7 @@
29642968

29652969
var thisObj, headingLevel, headingType, headingId, $chaptersHeading,
29662970
$chaptersNav, $chaptersList, $chapterItem, $chapterButton,
2967-
i, itemId, chapter, buttonId, hasDefault,
2971+
i, chapter, buttonId, hasDefault,
29682972
getClickFunction, $clickedItem, $chaptersList, thisChapterIndex;
29692973

29702974
thisObj = this;
@@ -2996,7 +3000,6 @@
29963000
$chaptersList = $('<ul>');
29973001
for (i in this.chapters) {
29983002
chapter = this.chapters[i];
2999-
itemId = this.mediaId + '-chapters-' + i; // TODO: Maybe not needed???
30003003
$chapterItem = $('<li></li>');
30013004
$chapterButton = $('<button>',{
30023005
'type': 'button',
@@ -4878,6 +4881,7 @@
48784881
var playerState = thisObj.getPlayerState(x.data);
48794882
if (playerState === 'playing') {
48804883
thisObj.playing = true;
4884+
thisObj.startedPlaying = true;
48814885
}
48824886
else {
48834887
thisObj.playing = false;
@@ -5195,22 +5199,24 @@
51955199
for (var i=0; i<options.length; i++) {
51965200
if (options[i] == 'cc') { // this is the AS3 (Flash) player
51975201
this.ytCaptionModule = 'cc';
5198-
this.hasCaptions = true;
5199-
this.usingYouTubeCaptions = true;
5202+
if (!this.hasCaptions) {
5203+
// there are captions available via other sources (e.g., <track>)
5204+
// so use these
5205+
this.hasCaptions = true;
5206+
this.usingYouTubeCaptions = true;
5207+
}
52005208
break;
52015209
}
52025210
else if (options[i] == 'captions') { // this is the HTML5 player
52035211
this.ytCaptionModule = 'captions';
5204-
this.hasCaptions = true;
5205-
this.usingYouTubeCaptions = true;
5212+
if (!this.hasCaptions) {
5213+
// there are captions available via other sources (e.g., <track>)
5214+
// so use these
5215+
this.hasCaptions = true;
5216+
this.usingYouTubeCaptions = true;
5217+
}
52065218
break;
52075219
}
5208-
else {
5209-
// no recognizable caption module was found
5210-
// sorry, gonna have to disable captions if we can't control them
5211-
this.hasCaptions = false;
5212-
this.usingYouTubeCaptions = false;
5213-
}
52145220
}
52155221
if (typeof this.ytCaptionModule !== 'undefined') {
52165222
if (this.usingYouTubeCaptions) {
@@ -7491,7 +7497,6 @@
74917497
};
74927498

74937499
AblePlayer.prototype.handleChapters = function () {
7494-
74957500
if (this.hidingPopup) {
74967501
// stopgap to prevent spacebar in Firefox from reopening popup
74977502
// immediately after closing it
@@ -8879,11 +8884,13 @@
88798884
};
88808885

88818886
AblePlayer.prototype.highlightTranscript = function (currentTime) {
8887+
8888+
//show highlight in transcript marking current caption
8889+
88828890
if (!this.transcriptType) {
88838891
return;
88848892
}
88858893

8886-
//show highlight in transcript marking current caption
88878894
var start, end;
88888895
var thisObj = this;
88898896

0 commit comments

Comments
 (0)