Skip to content

Commit

Permalink
Don't return variant/text tracks before playhead
Browse files Browse the repository at this point in the history
getVariantTracks and getTextTracks both check values on
player.playhead_, but don't check if the playhead exists beforehand.
This leads to problems when casting an encrypted asset; the cast status
update will check getVariantTracks and getTextTracks before the
playhead exists, and the error will make the status updates stop
coming.

Issue #1128

Change-Id: If38e586b1ea3006c01d3556216f5333d9eaf6e17
  • Loading branch information
theodab authored and joeyparrish committed Nov 27, 2017
1 parent 4503a2b commit e540653
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ shaka.Player.prototype.cancelTrickPlay = function() {
* @export
*/
shaka.Player.prototype.getVariantTracks = function() {
if (!this.manifest_)
if (!this.manifest_ || !this.playhead_)
return [];
this.assertCorrectActiveStreams_();

Expand All @@ -1312,7 +1312,7 @@ shaka.Player.prototype.getVariantTracks = function() {
* @export
*/
shaka.Player.prototype.getTextTracks = function() {
if (!this.manifest_)
if (!this.manifest_ || !this.playhead_)
return [];
this.assertCorrectActiveStreams_();

Expand Down
25 changes: 25 additions & 0 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,31 @@ describe('Player', function() {
expect(player.getTextTracks()).toEqual(textTracks);
});

it('returns empty arrays before tracks can be determined', function(done) {
var parser = new shaka.test.FakeManifestParser(manifest);
var parserFactory = function() { return parser; };
parser.start.and.callFake(function(manifestUri, playerInterface) {
// The player does not yet have a manifest.
expect(player.getVariantTracks()).toEqual([]);
expect(player.getTextTracks()).toEqual([]);

parser.playerInterface = playerInterface;
return Promise.resolve(manifest);
});
drmEngine.init.and.callFake(function(manifest, isOffline) {
// The player does not yet have a playhead.
expect(player.getVariantTracks()).toEqual([]);
expect(player.getTextTracks()).toEqual([]);
});

player.load('', 0, parserFactory).catch(fail).then(function() {
// Make sure the interruptions didn't mess up the tracks.
streamingEngine.onCanSwitch();
expect(player.getVariantTracks()).toEqual(variantTracks);
expect(player.getTextTracks()).toEqual(textTracks);
}).then(done);
});

it('doesn\'t disable AbrManager if switching variants', function() {
streamingEngine.onCanSwitch();

Expand Down

0 comments on commit e540653

Please sign in to comment.