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: player.duration() should return NaN if duration is not known #4443

Merged
merged 2 commits into from
Jun 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1747,10 +1747,11 @@ class Player extends Component {
*/
duration(seconds) {
if (seconds === undefined) {
return this.cache_.duration || 0;
// return NaN if the duration is not known
return this.cache_.duration !== undefined ? this.cache_.duration : NaN;
}

seconds = parseFloat(seconds) || 0;
seconds = parseFloat(seconds);
Copy link
Member

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.

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 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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

@alex-barstow alex-barstow Jun 27, 2017

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?

Copy link
Member

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.


// Standardize on Inifity for signaling video is live
if (seconds < 0) {
Expand Down