| |
| |
| |
| import MenuButton from '../../menu/menu-button.js'; |
| import PlaybackRateMenuItem from './playback-rate-menu-item.js'; |
| import Component from '../../component.js'; |
| import * as Dom from '../../utils/dom.js'; |
| |
| |
| |
| |
| |
| |
| |
| |
| class PlaybackRateMenuButton extends MenuButton { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| constructor(player, options) { |
| super(player, options); |
| |
| this.menuButton_.el_.setAttribute('aria-describedby', this.labelElId_); |
| |
| this.updateVisibility(); |
| this.updateLabel(); |
| |
| this.on(player, 'loadstart', (e) => this.updateVisibility(e)); |
| this.on(player, 'ratechange', (e) => this.updateLabel(e)); |
| this.on(player, 'playbackrateschange', (e) => this.handlePlaybackRateschange(e)); |
| } |
| |
| |
| |
| |
| |
| |
| |
| createEl() { |
| const el = super.createEl(); |
| |
| this.labelElId_ = 'vjs-playback-rate-value-label-' + this.id_; |
| |
| this.labelEl_ = Dom.createEl('div', { |
| className: 'vjs-playback-rate-value', |
| id: this.labelElId_, |
| textContent: '1x' |
| }); |
| |
| el.appendChild(this.labelEl_); |
| |
| return el; |
| } |
| |
| dispose() { |
| this.labelEl_ = null; |
| |
| super.dispose(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| buildCSSClass() { |
| return `vjs-playback-rate ${super.buildCSSClass()}`; |
| } |
| |
| buildWrapperCSSClass() { |
| return `vjs-playback-rate ${super.buildWrapperCSSClass()}`; |
| } |
| |
| |
| |
| |
| |
| createItems() { |
| const rates = this.playbackRates(); |
| const items = []; |
| |
| for (let i = rates.length - 1; i >= 0; i--) { |
| items.push(new PlaybackRateMenuItem(this.player(), {rate: rates[i] + 'x'})); |
| } |
| |
| return items; |
| } |
| |
| |
| |
| |
| |
| |
| handlePlaybackRateschange(event) { |
| this.update(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| playbackRates() { |
| const player = this.player(); |
| |
| return (player.playbackRates && player.playbackRates()) || []; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| playbackRateSupported() { |
| return this.player().tech_ && |
| this.player().tech_.featuresPlaybackRate && |
| this.playbackRates() && |
| this.playbackRates().length > 0 |
| ; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| updateVisibility(event) { |
| if (this.playbackRateSupported()) { |
| this.removeClass('vjs-hidden'); |
| } else { |
| this.addClass('vjs-hidden'); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| updateLabel(event) { |
| if (this.playbackRateSupported()) { |
| this.labelEl_.textContent = this.player().playbackRate() + 'x'; |
| } |
| } |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| PlaybackRateMenuButton.prototype.controlText_ = 'Playback Rate'; |
| |
| Component.registerComponent('PlaybackRateMenuButton', PlaybackRateMenuButton); |
| export default PlaybackRateMenuButton; |