Skip to content

Commit

Permalink
fix: do not preload default text track if preloadTextTracks is false (#…
Browse files Browse the repository at this point in the history
…7021)

When preloadTextTracks option is set to false, it still preloads the default text track. This leads to duplicate tracks once the mode changes to showing and the track is loaded a second time. This includes the default text track in the behavior defined by the preloadTextTracks option.

Fixes #7019
  • Loading branch information
isabelleingato authored Mar 9, 2021
1 parent 45eef66 commit b76e816
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/tracks/text-track.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class TextTrack extends Track {
// Act like we're loaded for other purposes.
this.loaded_ = true;
}
if (this.preload_ || default_ || (settings.kind !== 'subtitles' && settings.kind !== 'captions')) {
if (this.preload_ || (settings.kind !== 'subtitles' && settings.kind !== 'captions')) {
loadTrack(this.src, this);
}
} else {
Expand Down
46 changes: 46 additions & 0 deletions test/unit/tracks/text-track.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,52 @@ QUnit.test('enabled and disabled cuechange handler when changing mode to showing
player.dispose();
});

QUnit.test('if preloadTextTracks is false, default tracks are not parsed until mode is showing', function(assert) {
this.tech.preloadTextTracks = false;
const clock = sinon.useFakeTimers();
const oldVTT = window.WebVTT;
let parserCreated = false;
const reqs = [];

this.xhr.onCreate = function(req) {
reqs.push(req);
};

window.WebVTT = () => {};
window.WebVTT.StringDecoder = () => {};
window.WebVTT.Parser = () => {
parserCreated = true;
return {
oncue() {},
onparsingerror() {},
onflush() {},
parse() {},
flush() {}
};
};

const tt = new TextTrack({
tech: this.tech,
src: 'http://example.com',
default: true
});

assert.notOk(reqs.length, 'Default track is not requested');
assert.notOk(parserCreated, 'Parser is not created');

tt.mode = 'showing';

const req = reqs.pop();

req.respond(200, null, 'WEBVTT\n');

assert.ok(parserCreated, 'Parser is created after track is showing');

clock.restore();
tt.off();
window.WebVTT = oldVTT;
});

QUnit.test('tracks are parsed if vttjs is loaded', function(assert) {
const clock = sinon.useFakeTimers();
const oldVTT = window.WebVTT;
Expand Down

0 comments on commit b76e816

Please sign in to comment.