mirror of
https://github.com/videojs/video.js.git
synced 2024-11-24 08:42:25 +02:00
feat: display currentTime as duration and remainingTime as 0 on ended (#4634)
This commit is contained in:
parent
fa6f884409
commit
f51d36b053
@ -11,6 +11,20 @@ import Component from '../../component.js';
|
||||
*/
|
||||
class CurrentTimeDisplay extends TimeDisplay {
|
||||
|
||||
/**
|
||||
* Creates an instance of this class.
|
||||
*
|
||||
* @param {Player} player
|
||||
* The `Player` that this class should be attached to.
|
||||
*
|
||||
* @param {Object} [options]
|
||||
* The key/value store of player options.
|
||||
*/
|
||||
constructor(player, options) {
|
||||
super(player, options);
|
||||
this.on(player, 'ended', this.handleEnded);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the default DOM `className`.
|
||||
*
|
||||
@ -36,6 +50,23 @@ class CurrentTimeDisplay extends TimeDisplay {
|
||||
this.updateFormattedTime_(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* When the player fires ended there should be no time left. Sadly
|
||||
* this is not always the case, lets make it seem like that is the case
|
||||
* for users.
|
||||
*
|
||||
* @param {EventTarget~Event} [event]
|
||||
* The `ended` event that caused this to run.
|
||||
*
|
||||
* @listens Player#ended
|
||||
*/
|
||||
handleEnded(event) {
|
||||
if (!this.player_.duration()) {
|
||||
return;
|
||||
}
|
||||
this.updateFormattedTime_(this.player.duration());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,6 +22,7 @@ class RemainingTimeDisplay extends TimeDisplay {
|
||||
constructor(player, options) {
|
||||
super(player, options);
|
||||
this.on(player, 'durationchange', this.throttledUpdateContent);
|
||||
this.on(player, 'ended', this.handleEnded);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,6 +51,23 @@ class RemainingTimeDisplay extends TimeDisplay {
|
||||
|
||||
this.updateFormattedTime_(this.player_.remainingTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* When the player fires ended there should be no time left. Sadly
|
||||
* this is not always the case, lets make it seem like that is the case
|
||||
* for users.
|
||||
*
|
||||
* @param {EventTarget~Event} [event]
|
||||
* The `ended` event that caused this to run.
|
||||
*
|
||||
* @listens Player#ended
|
||||
*/
|
||||
handleEnded(event) {
|
||||
if (!this.player_.duration()) {
|
||||
return;
|
||||
}
|
||||
this.updateFormattedTime_(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user