Permalink
Browse files

fix(tracks): don't select tracks based on user pref if no langauge is…

… set (#5556)

When preselecting a new track based on user preference, make sure that the language is actually set and that the track we're testing is either a captions or a subtitles track.

Fixes #5553
  • Loading branch information...
gkatsev committed Nov 6, 2018
1 parent dbaca33 commit c1cbce386d5aed625945357fc34f874c5800e2d0
Showing with 49 additions and 2 deletions.
  1. +5 −2 src/js/tracks/text-track-display.js
  2. +44 −0 test/unit/tracks/text-track-display.test.js
@@ -150,8 +150,11 @@ class TextTrackDisplay extends Component {
for (let i = 0; i < trackList.length; i++) {
const track = trackList[i];

if (userPref && userPref.enabled &&
userPref.language === track.language) {
if (
userPref && userPref.enabled &&
userPref.language && userPref.language === track.language &&
track.kind in modes
) {
// Always choose the track that matches both language and kind
if (track.kind === userPref.kind) {
preferredTrack = track;
@@ -183,6 +183,50 @@ if (!Html5.supportsNativeTextTracks()) {
player.dispose();
});

QUnit.test("don't select user langauge if it is an empty string", function(assert) {
const player = TestHelpers.makePlayer();
const track1 = {
kind: 'captions',
label: 'English',
language: 'en',
src: 'en.vtt'
};
const track2 = {
kind: 'captions',
label: 'Spanish',
language: 'es',
src: 'es.vtt'
};
const track3 = {
kind: 'metadata',
label: 'segment-metadata'
};

player.src({type: 'video/mp4', src: 'http://google.com'});
// manualCleanUp = true by default
const englishTrack = player.addRemoteTextTrack(track1, true).track;
const spanishTrack = player.addRemoteTextTrack(track2, true).track;
const metadataTrack = player.addRemoteTextTrack(track3, true).track;

// Force empty string ('') as "user-selected" track
player.cache_.selectedLanguage = { enabled: true, language: '', kind: 'captions' };
this.clock.tick(1);

assert.equal(spanishTrack.mode, 'disabled', 'Spanish captions should be disabled');
assert.equal(englishTrack.mode, 'disabled', 'English captions should be disabled');
assert.notEqual(metadataTrack.mode, 'showing', 'Metadata track should not be showing');

// Force es as "user-selected" track
player.cache_.selectedLanguage = { enabled: true, language: 'es', kind: 'captions' };
player.trigger('loadstart');

assert.equal(spanishTrack.mode, 'showing', 'Spanish captions should be showing');
assert.equal(englishTrack.mode, 'disabled', 'English captions should be disabled');
assert.notEqual(metadataTrack.mode, 'showing', 'Metadata track should not be showing');

player.dispose();
});

QUnit.test("matching both the selectedLanguage's language and kind takes priority over just matching the language", function(assert) {
const player = TestHelpers.makePlayer();
const track1 = {

0 comments on commit c1cbce3

Please sign in to comment.