From ab4154c499f03d20fc20f1b194ba4b0adf8ede15 Mon Sep 17 00:00:00 2001 From: gaskeo Date: Fri, 28 Apr 2023 10:01:02 +0500 Subject: [PATCH 1/3] fix: fix multiple caption tracks for the same language --- src/js/captions.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/js/captions.js b/src/js/captions.js index c22a1ddb0..302bab0b8 100644 --- a/src/js/captions.js +++ b/src/js/captions.js @@ -148,8 +148,13 @@ const captions = { }); } + // Update track by track node if track and language exist + if (tracks.includes(currentTrackNode) && languageExists) { + captions.setNode.call(this, currentTrackNode); + captions.toggle.call(this, active && languageExists); + } // Update language first time it matches, or if the previous matching track was removed - if ((languageExists && this.language !== language) || !tracks.includes(currentTrackNode)) { + else if ((languageExists && this.language !== language) || !tracks.includes(currentTrackNode)) { captions.setLanguage.call(this, language); captions.toggle.call(this, active && languageExists); } @@ -286,6 +291,17 @@ const captions = { } }, + setNode(input, passive = true) { + if (!is.track(input)) { + this.debug.warn('Invalid track argument', input); + return; + } + + // Set currentTrack + const tracks = captions.getTracks.call(this); + captions.set.call(this, tracks.indexOf(input), passive); + }, + // Set captions by language // Used internally for the language setter with the passive option forced to false setLanguage(input, passive = true) { From c67261ef767fc3a609b11898945508c2d4a02e13 Mon Sep 17 00:00:00 2001 From: gaskeo Date: Fri, 28 Apr 2023 10:03:42 +0500 Subject: [PATCH 2/3] feat: add nodeTrack setter in plyr class for `captions.setNode` --- src/js/plyr.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/js/plyr.js b/src/js/plyr.js index 895b54ce8..14dca159c 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -968,6 +968,14 @@ class Plyr { return toggled ? currentTrack : -1; } + /** + * Set the wanted track node for captions + * @param {TextTrack} input - Two character ISO language code (e.g. EN, FR, PT, etc) + */ + set nodeTrack(input) { + captions.setNode.call(this, input, false); + } + /** * Set the wanted language for captions * Since tracks can be added later it won't update the actual caption track until there is a matching track From cc4c7d1772410c05ade6403cb2531b0e8701c2b3 Mon Sep 17 00:00:00 2001 From: gaskeo Date: Fri, 28 Apr 2023 10:17:38 +0500 Subject: [PATCH 3/3] feat: add nodeTrack declaration in `plyr.d.ts` --- src/js/plyr.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/js/plyr.d.ts b/src/js/plyr.d.ts index e81d97e7e..2db71080e 100644 --- a/src/js/plyr.d.ts +++ b/src/js/plyr.d.ts @@ -122,6 +122,11 @@ declare class Plyr { */ currentTrack: number; + /** + * Sets the preferred captions node for the player. + */ + nodeTrack: TextTrack; + /** * Gets or sets the preferred captions language for the player. The setter accepts an ISO twoletter language code. Support for the languages is dependent on the captions you include. * If your captions don't have any language data, or if you have multiple tracks with the same language, you may want to use currentTrack instead.