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

Conversation

ldayananda
Copy link
Contributor

@ldayananda ldayananda commented Jun 17, 2016

Description

Previously, if play is triggered before the video element has a source, Video.js would throw PLAYER_ERR_NO_SRC and this message would flash in the player briefly.

Specific Changes proposed

This checks whether the player has a source set on play, and if not, adds a loadstart handler to the tech to ensure that the source is loaded before playing.

Requirements Checklist

  • Bug fixed
  • Reviewed by Two Core Contributors

if (this.player_.currentSrc()) {
this.techCall_('play');
} else {
this.autoplay(true);
Copy link

Choose a reason for hiding this comment

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

What happens if the source is changed afterwards? Does that video autoplay too since we changed the setting?

Copy link
Member

Choose a reason for hiding this comment

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

Another potential issue, on firefox when you hit play without a source, autplay is still set to false: https://jsfiddle.net/gkatsev/xnm01byt/

Copy link
Member

Choose a reason for hiding this comment

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

And I just realized that if we want it to autoplay after a source is given, we need to make sure that the play event is fired when this is called but it isn't going to right now, I don't think...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With respect to the play event firing when autoplay is set, player.src(...) actually handles updating the video source and fires the play event if autoplay is true. In my general testing of this on different browsers, this seems to work.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, what I meant is that play should be fired when this function is called and not when the src is added and it starts playing.

@@ -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'

@ldayananda
Copy link
Contributor Author

Using .one at the player.js level as suggested by @gkatsev.

@@ -1292,7 +1292,15 @@ 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.

@ldayananda
Copy link
Contributor Author

Addressing potential holes when adblockers are used as per @gkatsev 's comment.

@gkatsev
Copy link
Member

gkatsev commented Jun 20, 2016

LGTM

@gkatsev gkatsev added minor This PR can be added to a minor release. It should not be added to a patch release. needs: LGTM Needs one or more additional approvals labels Jun 20, 2016
@misteroneill
Copy link
Member

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed minor This PR can be added to a minor release. It should not be added to a patch release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants