Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: duration reset and allow duration NaN or 0 for duration display (#…
…5348)

This allows the duration NaN or 0 to update the duration display.
This also resets the duration display when a new media item is loaded with `preload` set to 'none'.

Fixes #5347
  • Loading branch information
fketchakeu authored and gkatsev committed Nov 14, 2018
1 parent 0fb637d commit ab0e29a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/js/control-bar/time-controls/duration-display.js
Expand Up @@ -28,6 +28,11 @@ class DurationDisplay extends TimeDisplay {
// it has changed
this.on(player, 'durationchange', this.updateContent);

// Listen to loadstart because the player duration is reset when a new media element is loaded,
// but the durationchange on the user agent will not fire.
// @see [Spec]{@link https://www.w3.org/TR/2011/WD-html5-20110113/video.html#media-element-load-algorithm}
this.on(player, 'loadstart', this.updateContent);

// Also listen for timeupdate (in the parent) and loadedmetadata because removing those
// listeners could have broken dependent applications/libraries. These
// can likely be removed for 7.0.
Expand Down Expand Up @@ -58,7 +63,7 @@ class DurationDisplay extends TimeDisplay {
updateContent(event) {
const duration = this.player_.duration();

if (duration && this.duration_ !== duration) {
if (this.duration_ !== duration) {
this.duration_ = duration;
this.updateFormattedTime_(duration);
}
Expand Down
18 changes: 13 additions & 5 deletions src/js/player.js
Expand Up @@ -1290,6 +1290,9 @@ class Player extends Component {
// reset the error state
this.error(null);

// Update the duration
this.handleTechDurationChange_();

// If it's already playing we want to trigger a firstplay event now.
// The firstplay event relies on both the play and loadstart events
// which can happen in any order for a new source
Expand Down Expand Up @@ -2288,11 +2291,16 @@ class Player extends Component {
} else {
this.removeClass('vjs-live');
}
/**
* @event Player#durationchange
* @type {EventTarget~Event}
*/
this.trigger('durationchange');
if (!isNaN(seconds)) {
// Do not fire durationchange unless the duration value is known.
// @see [Spec]{@link https://www.w3.org/TR/2011/WD-html5-20110113/video.html#media-element-load-algorithm}

/**
* @event Player#durationchange
* @type {EventTarget~Event}
*/
this.trigger('durationchange');
}
}
}

Expand Down

0 comments on commit ab0e29a

Please sign in to comment.