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 the double loadstart event and fix it good #2605

Merged
merged 1 commit into from
Sep 18, 2015
Merged

Conversation

heff
Copy link
Member

@heff heff commented Sep 17, 2015

fixes #2588 @pat can you confirm?

Took me a day and half to fully wrap my brain around this. The code comments give some insight into the complexity.

With these changes you can now init a player on a video element of any loading state and the player will emit all the loading events, from loadstart to canplaythrough, to catch up to the current state.

// watch for that also.
let loadstartFired = false;
let setLoadstartFired = function() { loadstartFired = true; };
this.on('loadstart', setLoadstartFired);
Copy link
Member

Choose a reason for hiding this comment

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

maybe this.one?
Also, probably would've been a lot simpler with promises :P

Copy link
Member Author

Choose a reason for hiding this comment

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

one seemed unnecessary since we're always removing it on ready anyway. I guess it felt better to clean it up more manually, since not cleaning it up always would have really bad side effects.

@heff
Copy link
Member Author

heff commented Sep 17, 2015

@misteroneill would you be able to verify this?

(Sorry @pat, end of a long day)

@pat
Copy link

pat commented Sep 17, 2015

@heff no worries, it happens :)

@misteroneill
Copy link
Member

After attempting to verify: if you bind a listener before the player is ready, both "loadstart" and "ready" are fired twice. If you bind a listener on ready, both are fired once.

Here's the test code I used:

var vid = document.getElementById("vid1");
var player = videojs(vid).ready(function() {
  console.log('ready callback!');
});
player.on([
  'loadstart',
  'ready'
], function(event) {
  console.log(event.type);
});

Results in:

loadstart
ready
ready callback!
loadstart
ready

@heff
Copy link
Member Author

heff commented Sep 17, 2015

Thanks @misteroneill, these should be fixed now, if you get another second to try it. We had double ready triggers in the player. Not exactly sure how that happened.

@misteroneill
Copy link
Member

@heff Yeah, looking good now. 👍

 - Fixed some issue comments
 - Fixed a double ready event

closes videojs#2605
fixes videojs#2588
@heff heff merged commit 51bae4d into videojs:master Sep 18, 2015
@heff
Copy link
Member Author

heff commented Sep 18, 2015

Thanks @misteroneill!

@heff heff added this to the v5.0.0 milestone Sep 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

loadstart getting triggered twice
4 participants