playable
Version:
Video player based on HTML5Video
85 lines • 3.33 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var play_view_1 = (0, tslib_1.__importDefault)(require("./play.view"));
var keyboard_interceptor_1 = (0, tslib_1.__importStar)(require("../../../../utils/keyboard-interceptor"));
var constants_1 = require("../../../../constants");
var PlayControl = /** @class */ (function () {
function PlayControl(_a) {
var engine = _a.engine, eventEmitter = _a.eventEmitter, textMap = _a.textMap, theme = _a.theme;
this._engine = engine;
this._eventEmitter = eventEmitter;
this._textMap = textMap;
this._theme = theme;
this._bindCallbacks();
this._initUI();
this._bindEvents();
this._initInterceptor();
}
PlayControl.prototype.getElement = function () {
return this.view.getElement();
};
PlayControl.prototype._initInterceptor = function () {
var _a;
var _this = this;
this._interceptor = new keyboard_interceptor_1.default(this.getElement(), (_a = {},
_a[keyboard_interceptor_1.KEYCODES.SPACE_BAR] = function (e) {
e.stopPropagation();
_this._eventEmitter.emitAsync(constants_1.UIEvent.TOGGLE_PLAYBACK_WITH_KEYBOARD);
},
_a[keyboard_interceptor_1.KEYCODES.ENTER] = function (e) {
e.stopPropagation();
_this._eventEmitter.emitAsync(constants_1.UIEvent.TOGGLE_PLAYBACK_WITH_KEYBOARD);
},
_a));
};
PlayControl.prototype._destroyInterceptor = function () {
this._interceptor.destroy();
};
PlayControl.prototype._bindCallbacks = function () {
this._togglePlayback = this._togglePlayback.bind(this);
};
PlayControl.prototype._bindEvents = function () {
this._unbindEvents = this._eventEmitter.bindEvents([[constants_1.VideoEvent.STATE_CHANGED, this._updatePlayingState]], this);
};
PlayControl.prototype._togglePlayback = function () {
if (this._engine.isPaused) {
this._playVideo();
}
else {
this._pauseVideo();
}
};
PlayControl.prototype._playVideo = function () {
this._engine.play();
this._eventEmitter.emitAsync(constants_1.UIEvent.PLAY_CLICK);
};
PlayControl.prototype._pauseVideo = function () {
this._engine.pause();
this._eventEmitter.emitAsync(constants_1.UIEvent.PAUSE_CLICK);
};
PlayControl.prototype._updatePlayingState = function () {
this.view.setPlayingState(!this._engine.isPaused);
};
PlayControl.prototype._initUI = function () {
var config = {
callbacks: {
onButtonClick: this._togglePlayback,
},
theme: this._theme,
textMap: this._textMap,
};
this.view = new PlayControl.View(config);
};
PlayControl.prototype.destroy = function () {
this._destroyInterceptor();
this._unbindEvents();
this.view.destroy();
};
PlayControl.moduleName = 'playControl';
PlayControl.View = play_view_1.default;
PlayControl.dependencies = ['engine', 'eventEmitter', 'textMap', 'theme'];
return PlayControl;
}());
exports.default = PlayControl;
//# sourceMappingURL=play.js.map