Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NO_SRC when play is hit before the video elem src is set #3378

Closed
wants to merge 8 commits into from
12 changes: 11 additions & 1 deletion src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1292,10 +1292,20 @@ class Player extends Component {
* @method play
*/
play() {
this.techCall_('play');
// Only calls the tech's play if we already have a src loaded
if (this.player_.currentSrc()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to just do this.currentSrc() here, since the context is already the player itself. We also may want to do this.src() || this.currentSrc() to make sure that we catch issues where the src is set but currentSrc isn't (can happen when adblock is involved.

this.techCall_('play');
} else {
this.delayedPlay();
}

return this;
}

delayedPlay() {
this.techCall_('delayedPlay');
}

/**
* Pause the video playback
* ```js
Expand Down
6 changes: 6 additions & 0 deletions src/js/tech/tech.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ class Tech extends Component {
return createTimeRange();
}

delayedPlay() {
this.el_.onloadstart = function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should be able to do this.tech_.one('loadstart'

this.play();
};
}

/**
* Set current time
*
Expand Down
4 changes: 2 additions & 2 deletions test/unit/player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ test('should hide the poster when play is called', function() {
});

equal(player.hasStarted(), false, 'the show poster flag is true before play');
player.play();
player.tech_.trigger('play');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also fix this by mocking currentSrc()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was originally getting an error about the method currentSrc() not existing(likely since the tests use a fake tech.) I looked at how some of the other tests were written and saw that they almost exclusively trigger play in this way so I went with this instead.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's consistent with the other tests that seems reasonable

equal(player.hasStarted(), true, 'the show poster flag is false after play');

player.tech_.trigger('loadstart');
equal(player.hasStarted(),
false,
'the resource selection algorithm sets the show poster flag to true');

player.play();
player.tech_.trigger('play');
equal(player.hasStarted(), true, 'the show poster flag is false after play');
});

Expand Down