- 1 :
/**
- 2 :
* @file duration-display.js
- 3 :
*/
- 4 :
import TimeDisplay from './time-display';
- 5 :
import Component from '../../component.js';
- 6 :
- 7 :
/**
- 8 :
* Displays the duration
- 9 :
*
- 10 :
* @extends Component
- 11 :
*/
- 12 :
class DurationDisplay extends TimeDisplay {
- 13 :
- 14 :
/**
- 15 :
* Creates an instance of this class.
- 16 :
*
- 17 :
* @param { import('../../player').default } player
- 18 :
* The `Player` that this class should be attached to.
- 19 :
*
- 20 :
* @param {Object} [options]
- 21 :
* The key/value store of player options.
- 22 :
*/
- 23 :
constructor(player, options) {
- 24 :
super(player, options);
- 25 :
- 26 :
const updateContent = (e) => this.updateContent(e);
- 27 :
- 28 :
// we do not want to/need to throttle duration changes,
- 29 :
// as they should always display the changed duration as
- 30 :
// it has changed
- 31 :
this.on(player, 'durationchange', updateContent);
- 32 :
- 33 :
// Listen to loadstart because the player duration is reset when a new media element is loaded,
- 34 :
// but the durationchange on the user agent will not fire.
- 35 :
// @see [Spec]{@link https://www.w3.org/TR/2011/WD-html5-20110113/video.html#media-element-load-algorithm}
- 36 :
this.on(player, 'loadstart', updateContent);
- 37 :
- 38 :
// Also listen for timeupdate (in the parent) and loadedmetadata because removing those
- 39 :
// listeners could have broken dependent applications/libraries. These
- 40 :
// can likely be removed for 7.0.
- 41 :
this.on(player, 'loadedmetadata', updateContent);
- 42 :
}
- 43 :
- 44 :
/**
- 45 :
* Builds the default DOM `className`.
- 46 :
*
- 47 :
* @return {string}
- 48 :
* The DOM `className` for this object.
- 49 :
*/
- 50 :
buildCSSClass() {
- 51 :
return 'vjs-duration';
- 52 :
}
- 53 :
- 54 :
/**
- 55 :
* Update duration time display.
- 56 :
*
- 57 :
* @param {Event} [event]
- 58 :
* The `durationchange`, `timeupdate`, or `loadedmetadata` event that caused
- 59 :
* this function to be called.
- 60 :
*
- 61 :
* @listens Player#durationchange
- 62 :
* @listens Player#timeupdate
- 63 :
* @listens Player#loadedmetadata
- 64 :
*/
- 65 :
updateContent(event) {
- 66 :
const duration = this.player_.duration();
- 67 :
- 68 :
this.updateTextNode_(duration);
- 69 :
}
- 70 :
}
- 71 :
- 72 :
/**
- 73 :
* The text that is added to the `DurationDisplay` for screen reader users.
- 74 :
*
- 75 :
* @type {string}
- 76 :
* @private
- 77 :
*/
- 78 :
DurationDisplay.prototype.labelText_ = 'Duration';
- 79 :
- 80 :
/**
- 81 :
* The text that should display over the `DurationDisplay`s controls. Added to for localization.
- 82 :
*
- 83 :
* @type {string}
- 84 :
* @protected
- 85 :
*
- 86 :
* @deprecated in v7; controlText_ is not used in non-active display Components
- 87 :
*/
- 88 :
DurationDisplay.prototype.controlText_ = 'Duration';
- 89 :
- 90 :
Component.registerComponent('DurationDisplay', DurationDisplay);
- 91 :
export default DurationDisplay;