- 1 :
/**
- 2 :
* @file big-play-button.js
- 3 :
*/
- 4 :
import Button from './button.js';
- 5 :
import Component from './component.js';
- 6 :
import {isPromise, silencePromise} from './utils/promise';
- 7 :
import * as browser from './utils/browser.js';
- 8 :
- 9 :
/**
- 10 :
* The initial play button that shows before the video has played. The hiding of the
- 11 :
* `BigPlayButton` get done via CSS and `Player` states.
- 12 :
*
- 13 :
* @extends Button
- 14 :
*/
- 15 :
class BigPlayButton extends Button {
- 16 :
constructor(player, options) {
- 17 :
super(player, options);
- 18 :
- 19 :
this.mouseused_ = false;
- 20 :
- 21 :
this.on('mousedown', (e) => this.handleMouseDown(e));
- 22 :
}
- 23 :
- 24 :
/**
- 25 :
* Builds the default DOM `className`.
- 26 :
*
- 27 :
* @return {string}
- 28 :
* The DOM `className` for this object. Always returns 'vjs-big-play-button'.
- 29 :
*/
- 30 :
buildCSSClass() {
- 31 :
return 'vjs-big-play-button';
- 32 :
}
- 33 :
- 34 :
/**
- 35 :
* This gets called when a `BigPlayButton` "clicked". See {@link ClickableComponent}
- 36 :
* for more detailed information on what a click can be.
- 37 :
*
- 38 :
* @param {EventTarget~Event} event
- 39 :
* The `keydown`, `tap`, or `click` event that caused this function to be
- 40 :
* called.
- 41 :
*
- 42 :
* @listens tap
- 43 :
* @listens click
- 44 :
*/
- 45 :
handleClick(event) {
- 46 :
const playPromise = this.player_.play();
- 47 :
- 48 :
// exit early if clicked via the mouse
- 49 :
if (this.mouseused_ && event.clientX && event.clientY) {
- 50 :
const sourceIsEncrypted = this.player_.usingPlugin('eme') &&
- 51 :
this.player_.eme.sessions &&
- 52 :
this.player_.eme.sessions.length > 0;
- 53 :
- 54 :
silencePromise(playPromise);
- 55 :
if (this.player_.tech(true) &&
- 56 :
// We've observed a bug in IE and Edge when playing back DRM content where
- 57 :
// calling .focus() on the video element causes the video to go black,
- 58 :
// so we avoid it in that specific case
- 59 :
!((browser.IE_VERSION || browser.IS_EDGE) && sourceIsEncrypted)) {
- 60 :
this.player_.tech(true).focus();
- 61 :
}
- 62 :
return;
- 63 :
}
- 64 :
- 65 :
const cb = this.player_.getChild('controlBar');
- 66 :
const playToggle = cb && cb.getChild('playToggle');
- 67 :
- 68 :
if (!playToggle) {
- 69 :
this.player_.tech(true).focus();
- 70 :
return;
- 71 :
}
- 72 :
- 73 :
const playFocus = () => playToggle.focus();
- 74 :
- 75 :
if (isPromise(playPromise)) {
- 76 :
playPromise.then(playFocus, () => {});
- 77 :
} else {
- 78 :
this.setTimeout(playFocus, 1);
- 79 :
}
- 80 :
}
- 81 :
- 82 :
handleKeyDown(event) {
- 83 :
this.mouseused_ = false;
- 84 :
- 85 :
super.handleKeyDown(event);
- 86 :
}
- 87 :
- 88 :
handleMouseDown(event) {
- 89 :
this.mouseused_ = true;
- 90 :
}
- 91 :
}
- 92 :
- 93 :
/**
- 94 :
* The text that should display over the `BigPlayButton`s controls. Added to for localization.
- 95 :
*
- 96 :
* @type {string}
- 97 :
* @private
- 98 :
*/
- 99 :
BigPlayButton.prototype.controlText_ = 'Play Video';
- 100 :
- 101 :
Component.registerComponent('BigPlayButton', BigPlayButton);
- 102 :
export default BigPlayButton;