-
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: player.duration() should return NaN if duration is not known #4443
Conversation
} | ||
|
||
seconds = parseFloat(seconds) || 0; | ||
seconds = parseFloat(seconds); |
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.
I think in here we still want to do || 0
because if what is passed in, isn't a number we should just assume 0.
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.
I think the problem with leaving the || 0
is that if player.techGet_('duration')
equals NaN
when handleTechDurationChange_() is first called, then the initial value of player.cache_.duration
is 0 rather than NaN
. At least that was the case with the page I was testing with.
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.
Ah, I see. 🤔
I guess maybe this is fine since parseFloat()
will return NaN
for bad values. So, we'd just want to make sure the rest of this method handles NaN
correctly, if it doesn't already.
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.
Yeah, looks like this is fine but I think the duration display's updateDuration
method needs to be updated to account for NaN
values. Specifically, what happens if we start with unknown duration, transitioning from unknown duration to a known duration, and transitioning from a known duration to an unknown duration. That last one in particular I think might be problematic, though, not sure how common it is.
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.
This conditional will be false
if player.duration() = NaN
, so off the top of my head I can't think of a problem going from a unknown duration to a known duration. If we are transitioning from a known duration to an unknown duration, I believe the duration display (as currently written) would keep its previous 'known' state until the new duration becomes known and the display updates. Assuming I'm right about that, would this be acceptable behavior?
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.
Yeah, that's probably fine. Just wanted someone to think about it in some more depth.
I realized one thing that this is missing: tests :) |
@alex-barstow I pulled it in as is, but would be great to get some tests later, maybe when you get the 5.x PR ready. |
Description
player.duration()
currently returns 0 if the duration is not known, when it should returnNaN
. The problem is that ifNaN
is passed toplayer.duration()
as an argument, we set the duration to 0. Ifplayer.cache_.duration
was set toNaN
by other means,player.duration()
would still return 0. If approved, this will require a sister PR in the 5.x branch as well.Specific Changes proposed
Modify the player
duration()
method so that it will 1.) set the cached duration toNaN
if it is passed in as an argument, and 2.) return the proper value when called without an argument.Requirements Checklist