Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2608: multiple caption tracks for the same language are not available #2668

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/js/captions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/js/plyr.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions src/js/plyr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down