diff --git a/lib/player.js b/lib/player.js index 2e5bc92365b..4dc6945db9b 100644 --- a/lib/player.js +++ b/lib/player.js @@ -29,6 +29,7 @@ goog.require('shaka.media.SegmentReference'); goog.require('shaka.media.StreamingEngine'); goog.require('shaka.net.NetworkingEngine'); goog.require('shaka.text.SimpleTextDisplayer'); +goog.require('shaka.util.ArrayUtils'); goog.require('shaka.util.CancelableChain'); goog.require('shaka.util.ConfigUtils'); goog.require('shaka.util.Error'); @@ -2327,7 +2328,7 @@ shaka.Player.prototype.chooseStreams_ = } // Check if any of the active streams is no longer available - // or is using the wrong language. + // or is using the wrong language/role. var activeStreams = this.streamingEngine_.getActiveStreams(); // activePeriod may reasonably be null before StreamingEngine is streaming. var activePeriod = this.streamingEngine_.getActivePeriod(); @@ -2346,7 +2347,9 @@ shaka.Player.prototype.chooseStreams_ = for (var type in activeStreams) { var stream = activeStreams[type]; if (stream.type == ContentType.AUDIO && - stream.language != variants[0].language) { + (stream.language != variants[0].language || + !shaka.util.ArrayUtils.equal(stream.roles, + variants[0].audio.roles))) { needsUpdate.push(type); } else if (stream.type == ContentType.TEXT && textStreams.length > 0 && stream.language != textStreams[0].language) { diff --git a/test/player_unit.js b/test/player_unit.js index 8c6fec56a41..df49a8e3dd5 100644 --- a/test/player_unit.js +++ b/test/player_unit.js @@ -1033,7 +1033,7 @@ describe('Player', function() { .addVariant(3) .bandwidth(200) .language('en') - .addAudio(2).bandwidth(100) + .addAudio(2).bandwidth(100).roles(['secondary']) .addVideo(4).bandwidth(100).size(100, 200) .frameRate(1000000 / 42000) .addVariant(4) @@ -1122,7 +1122,7 @@ describe('Player', function() { audioCodec: 'mp4a.40.2', videoCodec: 'avc1.4d401f', primary: false, - roles: [], + roles: ['secondary'], videoId: 4, audioId: 2, channelsCount: null, @@ -1145,7 +1145,7 @@ describe('Player', function() { audioCodec: 'mp4a.40.2', videoCodec: 'avc1.4d401f', primary: false, - roles: [], + roles: ['secondary'], videoId: 5, audioId: 2, channelsCount: null, @@ -1285,6 +1285,25 @@ describe('Player', function() { ContentType.AUDIO, variant2.audio, false); }); + it('switches audio if tracks have different roles ', function() { + chooseStreams(); + canSwitch(); + + var period = manifest.periods[0]; + var variant1 = period.variants[0]; + var variant2 = period.variants[2]; + expect(shaka.util.ArrayUtils.equal( + variant1.audio.roles, variant2.audio.roles)).toBe(false); + + player.selectVariantTrack(variantTracks[0]); + streamingEngine.switch.calls.reset(); + + player.selectVariantTrack(variantTracks[2]); + + expect(streamingEngine.switch).toHaveBeenCalledWith( + ContentType.AUDIO, variant2.audio, false); + }); + it('doesn\'t switch video if old and new variants ' + 'have the same video track', function() { chooseStreams();