mirror of
https://github.com/videojs/video.js.git
synced 2025-02-06 11:51:07 +02:00
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
This commit is contained in:
parent
0fb637d16f
commit
ab0e29a431
@ -28,6 +28,11 @@ class DurationDisplay extends TimeDisplay {
|
|||||||
// it has changed
|
// it has changed
|
||||||
this.on(player, 'durationchange', this.updateContent);
|
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
|
// Also listen for timeupdate (in the parent) and loadedmetadata because removing those
|
||||||
// listeners could have broken dependent applications/libraries. These
|
// listeners could have broken dependent applications/libraries. These
|
||||||
// can likely be removed for 7.0.
|
// can likely be removed for 7.0.
|
||||||
@ -58,7 +63,7 @@ class DurationDisplay extends TimeDisplay {
|
|||||||
updateContent(event) {
|
updateContent(event) {
|
||||||
const duration = this.player_.duration();
|
const duration = this.player_.duration();
|
||||||
|
|
||||||
if (duration && this.duration_ !== duration) {
|
if (this.duration_ !== duration) {
|
||||||
this.duration_ = duration;
|
this.duration_ = duration;
|
||||||
this.updateFormattedTime_(duration);
|
this.updateFormattedTime_(duration);
|
||||||
}
|
}
|
||||||
|
@ -1290,6 +1290,9 @@ class Player extends Component {
|
|||||||
// reset the error state
|
// reset the error state
|
||||||
this.error(null);
|
this.error(null);
|
||||||
|
|
||||||
|
// Update the duration
|
||||||
|
this.handleTechDurationChange_();
|
||||||
|
|
||||||
// If it's already playing we want to trigger a firstplay event now.
|
// If it's already playing we want to trigger a firstplay event now.
|
||||||
// The firstplay event relies on both the play and loadstart events
|
// The firstplay event relies on both the play and loadstart events
|
||||||
// which can happen in any order for a new source
|
// which can happen in any order for a new source
|
||||||
@ -2288,6 +2291,10 @@ class Player extends Component {
|
|||||||
} else {
|
} else {
|
||||||
this.removeClass('vjs-live');
|
this.removeClass('vjs-live');
|
||||||
}
|
}
|
||||||
|
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
|
* @event Player#durationchange
|
||||||
* @type {EventTarget~Event}
|
* @type {EventTarget~Event}
|
||||||
@ -2295,6 +2302,7 @@ class Player extends Component {
|
|||||||
this.trigger('durationchange');
|
this.trigger('durationchange');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates how much time is left in the video. Not part
|
* Calculates how much time is left in the video. Not part
|
||||||
|
Loading…
x
Reference in New Issue
Block a user