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

feat: support vtt regions #6694

Open
wants to merge 4 commits into
base: main
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
13 changes: 10 additions & 3 deletions src/js/tracks/text-track-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ class TextTrackDisplay extends Component {
const tracks = this.player_.textTracks();
const allowMultipleShowingTracks = this.options_.allowMultipleShowingTracks;

this.clearDisplay();

if (allowMultipleShowingTracks) {
const showingTracks = [];

Expand Down Expand Up @@ -290,6 +288,8 @@ class TextTrackDisplay extends Component {
this.setAttribute('aria-live', 'assertive');
}
this.updateForTrack(descriptionsTrack);
} else {
this.clearDisplay();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary to clear the cues whenever we turn off all the captions. This makes it so that this PR is backward and forwards compatible.

}
}

Expand Down Expand Up @@ -397,6 +397,7 @@ class TextTrackDisplay extends Component {
}

const cues = [];
const regions = [];

// push all active track cues
for (let i = 0; i < tracks.length; ++i) {
Expand All @@ -405,10 +406,16 @@ class TextTrackDisplay extends Component {
for (let j = 0; j < track.activeCues.length; ++j) {
cues.push(track.activeCues[j]);
}

if (track.regionList) {
for (let j = 0; j < track.regionList.length; ++j) {
regions.push(track.regionList[j]);
}
}
}

// removes all cues before it processes new ones
window.WebVTT.processCues(window, cues, this.el_);
window.WebVTT.processCues(window, cues, this.el_, regions);

// add unique class to each language text track & add settings styling if necessary
for (let i = 0; i < tracks.length; ++i) {
Expand Down
6 changes: 6 additions & 0 deletions src/js/tracks/text-track.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,22 @@ const parseCues = function(srcContent, track) {
window.WebVTT.StringDecoder()
);
const errors = [];
const regions = [];

parser.oncue = function(cue) {
track.addCue(cue);
};

parser.onregion = function(region) {
regions.push(region);
};

parser.onparsingerror = function(error) {
errors.push(error);
};

parser.onflush = function() {
track.regionList = regions;
track.trigger({
type: 'loadeddata',
target: track
Expand Down