Skip to content

Commit

Permalink
fix(subtitles): set default property if default and autoselect are bo…
Browse files Browse the repository at this point in the history
…th enabled (#239)
  • Loading branch information
gkatsev authored and forbesjo committed Oct 25, 2018
1 parent ef98600 commit ee594e5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/media-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ export const initialize = {
const track = tech.addRemoteTextTrack({
id: variantLabel,
kind: 'subtitles',
enabled: false,
default: properties.default && properties.autoselect,
language: properties.language,
label: variantLabel
}, false).track;
Expand Down Expand Up @@ -568,7 +568,7 @@ export const initialize = {
const track = tech.addRemoteTextTrack({
id: properties.instreamId,
kind: 'captions',
enabled: false,
default: properties.default && properties.autoselect,
language: properties.language,
label: variantLabel
}, false).track;
Expand Down
104 changes: 63 additions & 41 deletions test/media-groups.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,55 +686,76 @@ function(assert) {
});

QUnit.test('initialize subtitles correctly generates tracks and playlist loaders',
function(assert) {
const type = 'SUBTITLES';
function(assert) {
const type = 'SUBTITLES';

this.master.mediaGroups[type].sub1 = {
'en': { language: 'en', resolvedUri: 'sub1/en.m3u8' },
'en-forced': { language: 'en', resolvedUri: 'sub1/en-forced.m3u8', forced: true },
'fr': { language: 'fr', resolvedUri: 'sub1/fr.m3u8' }
};
this.master.mediaGroups[type].sub2 = {
'en': { language: 'en', resolvedUri: 'sub2/en.m3u8' },
'en-forced': { language: 'en', resolvedUri: 'sub2/en-forced.m3u8', forced: true },
'fr': { language: 'fr', resolvedUri: 'sub2/fr.m3u8' }
};
this.master.mediaGroups[type].sub1 = {
'en': { language: 'en', default: true, resolvedUri: 'sub1/en.m3u8' },
'en-forced': { language: 'en', resolvedUri: 'sub1/en-forced.m3u8', forced: true },
'fr': { language: 'fr', resolvedUri: 'sub1/fr.m3u8' }
};
this.master.mediaGroups[type].sub2 = {
'en': { language: 'en', resolvedUri: 'sub2/en.m3u8' },
'en-forced': { language: 'en', resolvedUri: 'sub2/en-forced.m3u8', forced: true },
'fr': { language: 'fr', resolvedUri: 'sub2/fr.m3u8' }
};

MediaGroups.initialize[type](type, this.settings);
MediaGroups.initialize[type](type, this.settings);

assert.deepEqual(this.mediaTypes[type].groups,
{
sub1: [
{ id: 'en', language: 'en', default: true, resolvedUri: 'sub1/en.m3u8',
playlistLoader: this.mediaTypes[type].groups.sub1[0].playlistLoader },
{ id: 'fr', language: 'fr', resolvedUri: 'sub1/fr.m3u8',
playlistLoader: this.mediaTypes[type].groups.sub1[1].playlistLoader }
],
sub2: [
{ id: 'en', language: 'en', resolvedUri: 'sub2/en.m3u8',
playlistLoader: this.mediaTypes[type].groups.sub2[0].playlistLoader },
{ id: 'fr', language: 'fr', resolvedUri: 'sub2/fr.m3u8',
playlistLoader: this.mediaTypes[type].groups.sub2[1].playlistLoader }
]
}, 'creates group properties');
assert.ok(this.mediaTypes[type].groups.sub1[0].playlistLoader,
'playlistLoader created');
assert.ok(this.mediaTypes[type].groups.sub1[1].playlistLoader,
'playlistLoader created');
assert.ok(this.mediaTypes[type].groups.sub2[0].playlistLoader,
'playlistLoader created');
assert.ok(this.mediaTypes[type].groups.sub2[1].playlistLoader,
'playlistLoader created');
assert.ok(this.mediaTypes[type].tracks.en, 'created text track');
assert.equal(this.mediaTypes[type].tracks.en.default, undefined, 'No autoselect, no default');
assert.ok(this.mediaTypes[type].tracks.fr, 'created text track');
});

QUnit.test('initialize subtitles correctly with auto select',
function(assert) {
const type = 'SUBTITLES';

this.master.mediaGroups[type].sub1 = {
'en': { language: 'en', default: true, autoselect: true, resolvedUri: 'sub1/en.m3u8' },
'en-forced': { language: 'en', resolvedUri: 'sub1/en-forced.m3u8', forced: true },
'fr': { language: 'fr', resolvedUri: 'sub1/fr.m3u8' }
};
this.master.mediaGroups[type].sub2 = {
'en': { language: 'en', resolvedUri: 'sub2/en.m3u8' },
'en-forced': { language: 'en', resolvedUri: 'sub2/en-forced.m3u8', forced: true },
'fr': { language: 'fr', resolvedUri: 'sub2/fr.m3u8' }
};

assert.deepEqual(this.mediaTypes[type].groups,
{
sub1: [
{ id: 'en', language: 'en', resolvedUri: 'sub1/en.m3u8',
playlistLoader: this.mediaTypes[type].groups.sub1[0].playlistLoader },
{ id: 'fr', language: 'fr', resolvedUri: 'sub1/fr.m3u8',
playlistLoader: this.mediaTypes[type].groups.sub1[1].playlistLoader }
],
sub2: [
{ id: 'en', language: 'en', resolvedUri: 'sub2/en.m3u8',
playlistLoader: this.mediaTypes[type].groups.sub2[0].playlistLoader },
{ id: 'fr', language: 'fr', resolvedUri: 'sub2/fr.m3u8',
playlistLoader: this.mediaTypes[type].groups.sub2[1].playlistLoader }
]
}, 'creates group properties');
assert.ok(this.mediaTypes[type].groups.sub1[0].playlistLoader,
'playlistLoader created');
assert.ok(this.mediaTypes[type].groups.sub1[1].playlistLoader,
'playlistLoader created');
assert.ok(this.mediaTypes[type].groups.sub2[0].playlistLoader,
'playlistLoader created');
assert.ok(this.mediaTypes[type].groups.sub2[1].playlistLoader,
'playlistLoader created');
assert.ok(this.mediaTypes[type].tracks.en, 'created text track');
assert.ok(this.mediaTypes[type].tracks.fr, 'created text track');
});
MediaGroups.initialize[type](type, this.settings);

assert.equal(this.mediaTypes[type].tracks.en.default, true, 'en track auto selected');
});

QUnit.test('initialize closed-captions correctly generates tracks and NO loaders',
function(assert) {
const type = 'CLOSED-CAPTIONS';

this.master.mediaGroups[type].CCs = {
en608: { language: 'en', instreamId: 'CC1' },
en608: { language: 'en', default: true, autoselect: true, instreamId: 'CC1' },
en708: { language: 'en', instreamId: 'SERVICE1' },
fr608: { language: 'fr', instreamId: 'CC3' },
fr708: { language: 'fr', instreamId: 'SERVICE3' }
Expand All @@ -745,12 +766,13 @@ function(assert) {
assert.deepEqual(this.mediaTypes[type].groups,
{
CCs: [
{ id: 'en608', language: 'en', instreamId: 'CC1' },
{ id: 'en608', default: true, autoselect: true, language: 'en', instreamId: 'CC1' },
{ id: 'fr608', language: 'fr', instreamId: 'CC3' }
]
}, 'creates group properties');
assert.ok(this.mediaTypes[type].tracks.en608, 'created text track');
assert.ok(this.mediaTypes[type].tracks.fr608, 'created text track');
assert.equal(this.mediaTypes[type].tracks.en608.default, true, 'en608 track auto selected');
});

QUnit.test('initialize audio correctly uses HLS source type', function(assert) {
Expand Down

0 comments on commit ee594e5

Please sign in to comment.