mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-14 15:56:38 +03:00
bd167c3744
Co-authored-by: Wojciech Tyczyński <tykus160@gmail.com>
171 lines
4.3 KiB
JavaScript
171 lines
4.3 KiB
JavaScript
/*! @license
|
|
* Shaka Player
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
|
|
goog.provide('shaka.ui.CopyVideoFrameButton');
|
|
|
|
goog.require('shaka.ads.Utils');
|
|
goog.require('shaka.cast.CastProxy');
|
|
goog.require('shaka.ui.Controls');
|
|
goog.require('shaka.ui.Element');
|
|
goog.require('shaka.ui.Enums');
|
|
goog.require('shaka.ui.Icon');
|
|
goog.require('shaka.ui.Locales');
|
|
goog.require('shaka.ui.Localization');
|
|
goog.require('shaka.ui.OverflowMenu');
|
|
goog.require('shaka.ui.Utils');
|
|
goog.require('shaka.util.Dom');
|
|
goog.require('shaka.util.MediaElementEvent');
|
|
|
|
|
|
/**
|
|
* @extends {shaka.ui.Element}
|
|
* @final
|
|
* @export
|
|
*/
|
|
shaka.ui.CopyVideoFrameButton = class extends shaka.ui.Element {
|
|
/**
|
|
* @param {!HTMLElement} parent
|
|
* @param {!shaka.ui.Controls} controls
|
|
*/
|
|
constructor(parent, controls) {
|
|
super(parent, controls);
|
|
|
|
/** @private {shaka.cast.CastProxy} */
|
|
this.castProxy_ = this.controls.getCastProxy();
|
|
|
|
const LocIds = shaka.ui.Locales.Ids;
|
|
/** @private {!HTMLButtonElement} */
|
|
this.button_ = shaka.util.Dom.createButton();
|
|
this.button_.classList.add('shaka-copy-video-frame-button');
|
|
this.button_.classList.add('shaka-tooltip');
|
|
|
|
/** @private {!shaka.ui.Icon} */
|
|
this.icon_ = new shaka.ui.Icon(this.button_,
|
|
shaka.ui.Enums.MaterialDesignSVGIcons['COPY']);
|
|
|
|
const label = shaka.util.Dom.createHTMLElement('label');
|
|
label.classList.add('shaka-overflow-button-label');
|
|
label.classList.add('shaka-overflow-menu-only');
|
|
this.nameSpan_ = shaka.util.Dom.createHTMLElement('span');
|
|
this.nameSpan_.textContent =
|
|
this.localization.resolve(LocIds.COPY_VIDEO_FRAME);
|
|
label.appendChild(this.nameSpan_);
|
|
|
|
/** @private {!HTMLElement} */
|
|
this.currentState_ = shaka.util.Dom.createHTMLElement('span');
|
|
this.currentState_.classList.add('shaka-current-selection-span');
|
|
label.appendChild(this.currentState_);
|
|
|
|
this.button_.appendChild(label);
|
|
|
|
this.updateLocalizedStrings_();
|
|
|
|
this.parent.appendChild(this.button_);
|
|
|
|
this.eventManager.listenMulti(
|
|
this.localization,
|
|
[
|
|
shaka.ui.Localization.LOCALE_UPDATED,
|
|
shaka.ui.Localization.LOCALE_CHANGED,
|
|
], () => {
|
|
this.updateLocalizedStrings_();
|
|
});
|
|
|
|
this.eventManager.listen(this.button_, 'click', () => {
|
|
this.controls.copyVideoFrameToClipboard();
|
|
});
|
|
|
|
const vr = this.controls.getVR();
|
|
this.eventManager.listen(vr, 'vrstatuschanged', () => {
|
|
this.checkAvailability_();
|
|
});
|
|
|
|
this.eventManager.listenMulti(
|
|
this.adManager,
|
|
[
|
|
shaka.ads.Utils.AD_STARTED,
|
|
shaka.ads.Utils.AD_STOPPED,
|
|
], () => {
|
|
this.checkAvailability_();
|
|
});
|
|
|
|
this.eventManager.listenMulti(
|
|
this.player,
|
|
[
|
|
'unloading',
|
|
'loaded',
|
|
], () => {
|
|
this.checkAvailability_();
|
|
});
|
|
|
|
this.eventManager.listenMulti(
|
|
this.video,
|
|
[
|
|
shaka.util.MediaElementEvent.PLAY,
|
|
shaka.util.MediaElementEvent.PAUSE,
|
|
shaka.util.MediaElementEvent.SEEKING,
|
|
], () => {
|
|
this.checkAvailability_();
|
|
});
|
|
|
|
this.eventManager.listen(this.controls, 'caststatuschanged', () => {
|
|
this.checkAvailability_();
|
|
});
|
|
|
|
if (this.isSubMenu) {
|
|
this.eventManager.listenMulti(
|
|
this.controls,
|
|
[
|
|
'submenuopen',
|
|
'submenuclose',
|
|
], () => {
|
|
this.checkAvailability_();
|
|
});
|
|
}
|
|
|
|
this.checkAvailability_();
|
|
}
|
|
|
|
|
|
/**
|
|
* @private
|
|
*/
|
|
checkAvailability_() {
|
|
shaka.ui.Utils.setDisplay(this.button_,
|
|
this.controls.canCopyVideoFrameToClipboard() && !this.isSubMenuOpened);
|
|
}
|
|
|
|
|
|
/**
|
|
* @private
|
|
*/
|
|
updateLocalizedStrings_() {
|
|
const LocIds = shaka.ui.Locales.Ids;
|
|
|
|
this.button_.ariaLabel =
|
|
this.localization.resolve(LocIds.COPY_VIDEO_FRAME);
|
|
this.nameSpan_.textContent =
|
|
this.localization.resolve(LocIds.COPY_VIDEO_FRAME);
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
* @implements {shaka.extern.IUIElement.Factory}
|
|
* @final
|
|
*/
|
|
shaka.ui.CopyVideoFrameButton.Factory = class {
|
|
/** @override */
|
|
create(rootElement, controls) {
|
|
return new shaka.ui.CopyVideoFrameButton(rootElement, controls);
|
|
}
|
|
};
|
|
|
|
|
|
shaka.ui.OverflowMenu.registerElement(
|
|
'copy_video_frame', new shaka.ui.CopyVideoFrameButton.Factory());
|