Skip to content

Commit

Permalink
Update currentTextLanguage and currentAudioLanguage on track change.
Browse files Browse the repository at this point in the history
We've been asked to implement this to allow for a custom app
behavior where app exposes all the tracks independent of language
and role.
In that scenario changing audio language will affect current text
track and the other way around. This CL makes sure it doesn't.

Closes #1299.

Change-Id: I39a9748c033ea748173ca00bfa7168dff642a03e
  • Loading branch information
ismena committed Feb 22, 2018
1 parent 0640891 commit e8134ca
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,11 @@ shaka.Player.prototype.selectTextTrack = function(track) {
// Add entries to the history.
this.addTextStreamToSwitchHistory_(stream, /* fromAdaptation */ false);
this.switchTextStream_(stream);

// Workaround for https://github.com/google/shaka-player/issues/1299
// When track is selected, back-propogate the language to
// currentTextLanguage_.
this.currentTextLanguage_ = stream.language;
};


Expand Down Expand Up @@ -1340,6 +1345,11 @@ shaka.Player.prototype.selectVariantTrack = function(track, opt_clearBuffer) {
// Add entries to the history.
this.addVariantToSwitchHistory_(variant, /* fromAdaptation */ false);
this.switchVariant_(variant, opt_clearBuffer);

// Workaround for https://github.com/google/shaka-player/issues/1299
// When track is selected, back-propogate the language to
// currentAudioLanguage_.
this.currentAudioLanguage_ = variant.language;
};


Expand Down Expand Up @@ -1480,6 +1490,8 @@ shaka.Player.prototype.selectAudioLanguage =
let period = this.streamingEngine_.getCurrentPeriod();
this.currentAudioLanguage_ = language;
this.currentVariantRole_ = opt_role || '';
// TODO: refactor to only change audio and not affect
// text.
this.chooseStreamsAndSwitch_(period);
};

Expand All @@ -1498,6 +1510,8 @@ shaka.Player.prototype.selectTextLanguage =
let period = this.streamingEngine_.getCurrentPeriod();
this.currentTextLanguage_ = language;
this.currentTextRole_ = opt_role || '';
// TODO: refactor to only change text and not affect
// audio.
this.chooseStreamsAndSwitch_(period);
};

Expand Down
28 changes: 28 additions & 0 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,34 @@ describe('Player', function() {
expect(getActiveVariantTrack().roles[0]).toBe('commentary');
});

it('selectAudioLanguage() does not change selected text track',
function() {
// This came up in a custom application that allows to select
// from all tracks regardless of selected language.
// We imitate this behavior by calling selectTextLanguage()
// with one language and then selecting a track in a different
// language.
player.selectTextLanguage('en');
expect(textTracks[0].language).toBe('es');
player.selectTextTrack(textTracks[0]);
player.selectAudioLanguage('es');
expect(getActiveTextTrack().id).toBe(textTracks[0].id);
});

it('selectTextLanguage() does not change selected variant track',
function() {
// This came up in a custom application that allows to select
// from all tracks regardless of selected language.
// We imitate this behavior by calling selectAudioLanguage()
// with one language and then selecting a track in a different
// language.
player.selectAudioLanguage('es');
expect(variantTracks[0].language).toBe('en');
player.selectVariantTrack(variantTracks[0]);
player.selectTextLanguage('es');
expect(getActiveVariantTrack().id).toBe(variantTracks[0].id);
});

it('selectTextLanguage() takes precedence over ' +
'preferredTextLanguage', function() {
streamingEngine.onCanSwitch();
Expand Down

0 comments on commit e8134ca

Please sign in to comment.