-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Conversation
…player to autoplay as the src is set
if (this.player_.currentSrc()) { | ||
this.techCall_('play'); | ||
} else { | ||
this.autoplay(true); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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/
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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'
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()) { |
There was a problem hiding this comment.
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.
…in case adblock is used.
Addressing potential holes when adblockers are used as per @gkatsev 's comment. |
LGTM |
LGTM |
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