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 1 commit
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
Next Next commit
region support
  • Loading branch information
gkatsev committed Oct 6, 2020
commit 11ab7ec82932500c0d40de441eb27e02715b0c10
9 changes: 8 additions & 1 deletion src/js/tracks/text-track-display.js
Original file line number Diff line number Diff line change
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