Skip to content

Commit 2a54e68

Browse files
committed
Add described version swapping features to YouTube player
1 parent 2e44cfa commit 2a54e68

11 files changed

Lines changed: 94 additions & 38 deletions

build/ableplayer.dist.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
}
135135

136136
if ($(media).data('youtube-id') !== undefined && $(media).data('youtube-id') !== "") {
137-
this.youtubeId = $(media).data('youtube-id');
137+
this.youTubeId = $(media).data('youtube-id');
138138
}
139139

140140
if ($(media).data('youtube-desc-id') !== undefined && $(media).data('youtube-desc-id') !== "") {
@@ -844,7 +844,7 @@
844844
// Determine which player to use, if any
845845
// return 'html5', 'jw' or null
846846
var i, sourceType, $newItem;
847-
if (this.youtubeId) {
847+
if (this.youTubeId) {
848848
if (this.mediaType !== 'video') {
849849
return null;
850850
}
@@ -4171,7 +4171,7 @@
41714171
youTubeId = this.youTubeDescId;
41724172
}
41734173
else {
4174-
youTubeId = this.youtubeId;
4174+
youTubeId = this.youTubeId;
41754175
}
41764176
this.activeYouTubeId = youTubeId;
41774177

@@ -4341,7 +4341,7 @@
43414341
youTubeId = this.youTubeDescId;
43424342
}
43434343
else {
4344-
youTubeId = this.youtubeId;
4344+
youTubeId = this.youTubeId;
43454345
}
43464346

43474347
// Wait until Google Client API is loaded
@@ -4369,7 +4369,6 @@
43694369
};
43704370

43714371
AblePlayer.prototype.getYouTubeCaptionData = function (youTubeId) {
4372-
43734372
// get data via YouTube Data API, and push data to this.ytCaptions
43744373

43754374
var deferred = new $.Deferred();
@@ -4450,7 +4449,6 @@
44504449
};
44514450

44524451
AblePlayer.prototype.initYouTubeCaptionModule = function () {
4453-
44544452
// This function is called when YouTube onApiChange event fires
44554453
// to indicate that the player has loaded (or unloaded) a module with exposed API methods
44564454
// it isn't fired until the video starts playing
@@ -5587,7 +5585,6 @@
55875585
};
55885586

55895587
AblePlayer.prototype.swapDescription = function() {
5590-
55915588
// swap described and non-described source media, depending on which is playing
55925589
// this function is only called in two circumstances:
55935590
// 1. Swapping to described version when initializing player (based on user prefs & availability)
@@ -5613,7 +5610,6 @@
56135610
if (this.player === 'html5') {
56145611

56155612
if (this.usingAudioDescription()) {
5616-
56175613
// the described version is currently playing. Swap to non-described
56185614
for (i=0; i < this.$sources.length; i++) {
56195615
// for all <source> elements, replace src with data-orig-src
@@ -5632,7 +5628,6 @@
56325628
this.swappingSrc = true;
56335629
}
56345630
else {
5635-
56365631
// the non-described version is currently playing. Swap to described.
56375632
for (i=0; i < this.$sources.length; i++) {
56385633
// for all <source> elements, replace src with data-desc-src (if one exists)
@@ -5663,6 +5658,29 @@
56635658
this.jwPlayer.load({file: newSource});
56645659
}
56655660
}
5661+
else if (this.player === 'youtube') {
5662+
5663+
if (this.usingAudioDescription()) {
5664+
// the described version is currently playing. Swap to non-described
5665+
this.activeYouTubeId = this.youTubeId;
5666+
this.showAlert(this.tt.alertNonDescribedVersion);
5667+
}
5668+
else {
5669+
// the non-described version is currently playing. Swap to described.
5670+
this.activeYouTubeId = this.youTubeDescId;
5671+
this.showAlert(this.tt.alertDescribedVersion);
5672+
}
5673+
if (typeof this.youTubePlayer !== 'undefined') {
5674+
if (this.playing) {
5675+
// loadVideoById() loads and immediately plays the new video at swapTime
5676+
this.youTubePlayer.loadVideoById(this.activeYouTubeId,this.swapTime);
5677+
}
5678+
else {
5679+
// cueVideoById() loads the new video and seeks to swapTime, but does not play
5680+
this.youTubePlayer.cueVideoById(this.activeYouTubeId,this.swapTime);
5681+
}
5682+
}
5683+
}
56665684
};
56675685

56685686
AblePlayer.prototype.showDescription = function(now) {
@@ -6939,7 +6957,7 @@
69396957

69406958
(function ($) {
69416959
AblePlayer.prototype.updateCaption = function (time) {
6942-
if (!this.usingYouTubeCaptions) {
6960+
if (!this.usingYouTubeCaptions && (typeof this.$captionDiv !== 'undefined')) {
69436961
if (this.captionsOn) {
69446962
this.$captionDiv.show();
69456963
this.showCaptions(time || this.getElapsed());

build/ableplayer.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
}
135135

136136
if ($(media).data('youtube-id') !== undefined && $(media).data('youtube-id') !== "") {
137-
this.youtubeId = $(media).data('youtube-id');
137+
this.youTubeId = $(media).data('youtube-id');
138138
}
139139

140140
if ($(media).data('youtube-desc-id') !== undefined && $(media).data('youtube-desc-id') !== "") {
@@ -844,7 +844,7 @@
844844
// Determine which player to use, if any
845845
// return 'html5', 'jw' or null
846846
var i, sourceType, $newItem;
847-
if (this.youtubeId) {
847+
if (this.youTubeId) {
848848
if (this.mediaType !== 'video') {
849849
return null;
850850
}
@@ -4171,7 +4171,7 @@
41714171
youTubeId = this.youTubeDescId;
41724172
}
41734173
else {
4174-
youTubeId = this.youtubeId;
4174+
youTubeId = this.youTubeId;
41754175
}
41764176
this.activeYouTubeId = youTubeId;
41774177

@@ -4341,7 +4341,7 @@
43414341
youTubeId = this.youTubeDescId;
43424342
}
43434343
else {
4344-
youTubeId = this.youtubeId;
4344+
youTubeId = this.youTubeId;
43454345
}
43464346

43474347
// Wait until Google Client API is loaded
@@ -4369,7 +4369,6 @@
43694369
};
43704370

43714371
AblePlayer.prototype.getYouTubeCaptionData = function (youTubeId) {
4372-
43734372
// get data via YouTube Data API, and push data to this.ytCaptions
43744373

43754374
var deferred = new $.Deferred();
@@ -4450,7 +4449,6 @@
44504449
};
44514450

44524451
AblePlayer.prototype.initYouTubeCaptionModule = function () {
4453-
44544452
// This function is called when YouTube onApiChange event fires
44554453
// to indicate that the player has loaded (or unloaded) a module with exposed API methods
44564454
// it isn't fired until the video starts playing
@@ -5587,7 +5585,6 @@
55875585
};
55885586

55895587
AblePlayer.prototype.swapDescription = function() {
5590-
55915588
// swap described and non-described source media, depending on which is playing
55925589
// this function is only called in two circumstances:
55935590
// 1. Swapping to described version when initializing player (based on user prefs & availability)
@@ -5613,7 +5610,6 @@
56135610
if (this.player === 'html5') {
56145611

56155612
if (this.usingAudioDescription()) {
5616-
56175613
// the described version is currently playing. Swap to non-described
56185614
for (i=0; i < this.$sources.length; i++) {
56195615
// for all <source> elements, replace src with data-orig-src
@@ -5632,7 +5628,6 @@
56325628
this.swappingSrc = true;
56335629
}
56345630
else {
5635-
56365631
// the non-described version is currently playing. Swap to described.
56375632
for (i=0; i < this.$sources.length; i++) {
56385633
// for all <source> elements, replace src with data-desc-src (if one exists)
@@ -5663,6 +5658,29 @@
56635658
this.jwPlayer.load({file: newSource});
56645659
}
56655660
}
5661+
else if (this.player === 'youtube') {
5662+
5663+
if (this.usingAudioDescription()) {
5664+
// the described version is currently playing. Swap to non-described
5665+
this.activeYouTubeId = this.youTubeId;
5666+
this.showAlert(this.tt.alertNonDescribedVersion);
5667+
}
5668+
else {
5669+
// the non-described version is currently playing. Swap to described.
5670+
this.activeYouTubeId = this.youTubeDescId;
5671+
this.showAlert(this.tt.alertDescribedVersion);
5672+
}
5673+
if (typeof this.youTubePlayer !== 'undefined') {
5674+
if (this.playing) {
5675+
// loadVideoById() loads and immediately plays the new video at swapTime
5676+
this.youTubePlayer.loadVideoById(this.activeYouTubeId,this.swapTime);
5677+
}
5678+
else {
5679+
// cueVideoById() loads the new video and seeks to swapTime, but does not play
5680+
this.youTubePlayer.cueVideoById(this.activeYouTubeId,this.swapTime);
5681+
}
5682+
}
5683+
}
56665684
};
56675685

56685686
AblePlayer.prototype.showDescription = function(now) {
@@ -6939,7 +6957,7 @@
69396957

69406958
(function ($) {
69416959
AblePlayer.prototype.updateCaption = function (time) {
6942-
if (!this.usingYouTubeCaptions) {
6960+
if (!this.usingYouTubeCaptions && (typeof this.$captionDiv !== 'undefined')) {
69436961
if (this.captionsOn) {
69446962
this.$captionDiv.show();
69456963
this.showCaptions(time || this.getElapsed());

0 commit comments

Comments
 (0)