Skip to content

Commit

Permalink
fix: player.duration() should return NaN if duration is not known (#4443
Browse files Browse the repository at this point in the history
)

player.duration() currently returns 0 if the duration is not known, when it should return NaN. The problem is that if NaN is passed to player.duration() as an argument, we set the duration to 0. If player.cache_.duration was set to NaN by other means, player.duration() would still return 0.

Modify the player duration() method so that it will 1.) set the cached duration to NaN if it is passed in as an argument, and 2.) return the proper value when called without an argument.
  • Loading branch information
alex-barstow authored and gkatsev committed Jun 28, 2017
1 parent b4dc4f8 commit f5cc165
Showing 1 changed file with 3 additions and 2 deletions.
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);

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

0 comments on commit f5cc165

Please sign in to comment.