diff --git a/src/media-groups.js b/src/media-groups.js index 918026aad..6a3124b08 100644 --- a/src/media-groups.js +++ b/src/media-groups.js @@ -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; @@ -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; diff --git a/test/media-groups.test.js b/test/media-groups.test.js index 3aa4261e8..f83c0427e 100644 --- a/test/media-groups.test.js +++ b/test/media-groups.test.js @@ -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' } @@ -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) {