Skip to content

Commit ab0e29a

Browse files
fketchakeugkatsev
authored andcommitted
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
1 parent 0fb637d commit ab0e29a

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/js/control-bar/time-controls/duration-display.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class DurationDisplay extends TimeDisplay {
2828
// it has changed
2929
this.on(player, 'durationchange', this.updateContent);
3030

31+
// Listen to loadstart because the player duration is reset when a new media element is loaded,
32+
// but the durationchange on the user agent will not fire.
33+
// @see [Spec]{@link https://www.w3.org/TR/2011/WD-html5-20110113/video.html#media-element-load-algorithm}
34+
this.on(player, 'loadstart', this.updateContent);
35+
3136
// Also listen for timeupdate (in the parent) and loadedmetadata because removing those
3237
// listeners could have broken dependent applications/libraries. These
3338
// can likely be removed for 7.0.
@@ -58,7 +63,7 @@ class DurationDisplay extends TimeDisplay {
5863
updateContent(event) {
5964
const duration = this.player_.duration();
6065

61-
if (duration && this.duration_ !== duration) {
66+
if (this.duration_ !== duration) {
6267
this.duration_ = duration;
6368
this.updateFormattedTime_(duration);
6469
}

src/js/player.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,9 @@ class Player extends Component {
12901290
// reset the error state
12911291
this.error(null);
12921292

1293+
// Update the duration
1294+
this.handleTechDurationChange_();
1295+
12931296
// If it's already playing we want to trigger a firstplay event now.
12941297
// The firstplay event relies on both the play and loadstart events
12951298
// which can happen in any order for a new source
@@ -2288,11 +2291,16 @@ class Player extends Component {
22882291
} else {
22892292
this.removeClass('vjs-live');
22902293
}
2291-
/**
2292-
* @event Player#durationchange
2293-
* @type {EventTarget~Event}
2294-
*/
2295-
this.trigger('durationchange');
2294+
if (!isNaN(seconds)) {
2295+
// Do not fire durationchange unless the duration value is known.
2296+
// @see [Spec]{@link https://www.w3.org/TR/2011/WD-html5-20110113/video.html#media-element-load-algorithm}
2297+
2298+
/**
2299+
* @event Player#durationchange
2300+
* @type {EventTarget~Event}
2301+
*/
2302+
this.trigger('durationchange');
2303+
}
22962304
}
22972305
}
22982306

0 commit comments

Comments
 (0)