Skip to content

Commit

Permalink
fix: choose the configured preferred text role at start (shaka-projec…
Browse files Browse the repository at this point in the history
  • Loading branch information
valotvince committed May 11, 2021
1 parent 69c310c commit d47c823
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions demo/common/message_ids.js
Expand Up @@ -228,6 +228,7 @@ shakaDemo.MessageIds = {
STREAMING_SECTION_HEADER: 'DEMO_STREAMING_SECTION_HEADER',
SWITCH_INTERVAL: 'DEMO_SWITCH_INTERVAL',
TEXT_LANGUAGE: 'DEMO_TEXT_LANGUAGE',
TEXT_ROLE: 'DEMO_TEXT_ROLE',
TIMEOUT: 'DEMO_TIMEOUT',
TRICK_PLAY_CONTROLS: 'DEMO_TRICK_PLAY_CONTROLS',
TRICK_PLAY_CONTROLS_WARNING: 'DEMO_TRICK_PLAY_CONTROLS_WARNING',
Expand Down
3 changes: 2 additions & 1 deletion demo/config.js
Expand Up @@ -395,7 +395,8 @@ shakaDemo.Config = class {
const docLink = this.resolveExternLink_('.PlayerConfiguration');
this.addSection_(MessageIds.LANGUAGE_SECTION_HEADER, docLink)
.addTextInput_(MessageIds.AUDIO_LANGUAGE, 'preferredAudioLanguage')
.addTextInput_(MessageIds.TEXT_LANGUAGE, 'preferredTextLanguage');
.addTextInput_(MessageIds.TEXT_LANGUAGE, 'preferredTextLanguage')
.addTextInput_(MessageIds.TEXT_ROLE, 'preferredTextRole');
const onChange = (input) => {
shakaDemoMain.setUILocale(input.value);
shakaDemoMain.remakeHash();
Expand Down
1 change: 1 addition & 0 deletions demo/demo_utils.js
Expand Up @@ -38,6 +38,7 @@ shakaDemo.Utils = class {
// Override config values with custom names.
configOverride('audiolang', 'preferredAudioLanguage');
configOverride('textlang', 'preferredTextLanguage');
configOverride('textrole', 'preferredTextRole');
configOverride('channels', 'preferredAudioChannelCount');

// Override config values that are handled manually.
Expand Down
1 change: 1 addition & 0 deletions demo/locales/en.json
Expand Up @@ -187,6 +187,7 @@
"DEMO_SURROUND_SEARCH": "Filters for assets with at least one surround sound audio track.",
"DEMO_SWITCH_INTERVAL": "Switch Interval",
"DEMO_TEXT_LANGUAGE": "Preferred Text Language",
"DEMO_TEXT_ROLE": "Preferred Text Role",
"DEMO_THUMBNAILS": "Thumbnails",
"DEMO_TIMEOUT": "Timeout Factor",
"DEMO_TRICK_MODE": "Special trick mode track",
Expand Down
4 changes: 4 additions & 0 deletions demo/locales/source.json
Expand Up @@ -755,6 +755,10 @@
"description": "The name of a configuration value.",
"message": "Preferred Text Language"
},
"DEMO_TEXT_ROLE": {
"description": "The name of a configuration value.",
"message": "Preferred Text Role"
},
"DEMO_THUMBNAILS": {
"description": "Text that describes an asset that has a thumbnail stream.",
"message": "Thumbnails"
Expand Down
1 change: 1 addition & 0 deletions lib/player.js
Expand Up @@ -1826,6 +1826,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
this.config_.preferredAudioChannelCount);

this.currentTextLanguage_ = this.config_.preferredTextLanguage;
this.currentTextRole_ = this.config_.preferredTextRole;

shaka.Player.applyPlayRange_(this.manifest_.presentationTimeline,
this.config_.playRangeStart,
Expand Down
1 change: 0 additions & 1 deletion test/demo/demo_unit.js
Expand Up @@ -96,7 +96,6 @@ describe('Demo', () => {
const configPrimitives = new Set(['number', 'string', 'boolean']);
const exceptions = new Set()
.add('preferredVariantRole')
.add('preferredTextRole')
.add('playRangeStart')
.add('playRangeEnd')
.add('manifest.dash.keySystemsByURI');
Expand Down
18 changes: 18 additions & 0 deletions test/player_unit.js
Expand Up @@ -1986,6 +1986,24 @@ describe('Player', () => {
expect(variantChanged).not.toHaveBeenCalled();
});
});

it('chooses the configured text language and role at start', async () => {
player.configure({
preferredTextLanguage: 'en',
preferredTextRole: 'commentary',
});

await player.load(fakeManifestUri, 0, fakeMimeType);

// Text was turned on during startup.
expect(player.isTextTrackVisible()).toBe(true);

expect(getActiveTextTrack()).toEqual(jasmine.objectContaining({
id: 52,
language: 'en',
roles: ['commentary'],
}));
});
}); // describe('tracks')

describe('languages', () => {
Expand Down

0 comments on commit d47c823

Please sign in to comment.