UNPKG

playable

Version:

Video player based on HTML5Video

127 lines 4.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UPDATE_TIME_INTERVAL_DELAY = void 0; var tslib_1 = require("tslib"); var time_view_1 = (0, tslib_1.__importDefault)(require("./time.view")); var constants_1 = require("../../../../constants"); exports.UPDATE_TIME_INTERVAL_DELAY = 1000 / 60; var TimeControl = /** @class */ (function () { function TimeControl(_a) { var eventEmitter = _a.eventEmitter, engine = _a.engine, theme = _a.theme; this._eventEmitter = eventEmitter; this._engine = engine; this._theme = theme; this._bindCallbacks(); this._initUI(); this._bindEvents(); this._setCurrentTime(0); this._setDurationTime(0); } TimeControl.prototype.getElement = function () { return this.view.getElement(); }; TimeControl.prototype._bindCallbacks = function () { this._updateCurrentTime = this._updateCurrentTime.bind(this); this._updateDurationTime = this._updateDurationTime.bind(this); }; TimeControl.prototype._bindEvents = function () { this._unbindEvents = this._eventEmitter.bindEvents([ [constants_1.UIEvent.PROGRESS_USER_PREVIEWING_FRAME, this._updateTimeFromPreview], [constants_1.VideoEvent.STATE_CHANGED, this._toggleIntervalUpdates], [constants_1.VideoEvent.DURATION_UPDATED, this._updateDurationTime], [constants_1.VideoEvent.LIVE_STATE_CHANGED, this._processLiveStateChange], ], this); }; TimeControl.prototype._initUI = function () { var config = { theme: this._theme, }; this.view = new TimeControl.View(config); }; TimeControl.prototype._startIntervalUpdates = function () { if (this._updateControlInterval) { this._stopIntervalUpdates(); } this._updateCurrentTime(); this._updateControlInterval = window.setInterval(this._updateCurrentTime, exports.UPDATE_TIME_INTERVAL_DELAY); }; TimeControl.prototype._stopIntervalUpdates = function () { window.clearInterval(this._updateControlInterval); this._updateControlInterval = null; }; TimeControl.prototype._processLiveStateChange = function (_a) { var nextState = _a.nextState; switch (nextState) { case constants_1.LiveState.NONE: this.show(); break; case constants_1.LiveState.INITIAL: this.hide(); break; case constants_1.LiveState.ENDED: this.show(); break; default: break; } }; TimeControl.prototype._toggleIntervalUpdates = function (_a) { var nextState = _a.nextState; switch (nextState) { case constants_1.EngineState.SRC_SET: this.reset(); break; case constants_1.EngineState.PLAYING: this._startIntervalUpdates(); break; case constants_1.EngineState.SEEK_IN_PROGRESS: this._startIntervalUpdates(); break; default: this._stopIntervalUpdates(); break; } }; TimeControl.prototype._updateDurationTime = function () { this._setDurationTime(this._engine.getDuration()); }; TimeControl.prototype._updateCurrentTime = function () { var time = this._engine.getCurrentTime(); this._setCurrentTime(time); }; TimeControl.prototype._updateTimeFromPreview = function (time) { this.view.setCurrentTime(time); }; TimeControl.prototype._setDurationTime = function (time) { this.view.setDurationTime(time); }; TimeControl.prototype._setCurrentTime = function (time) { this.view.setCurrentTime(time); }; TimeControl.prototype.hide = function () { this.isHidden = true; this.view.hide(); }; TimeControl.prototype.show = function () { this.isHidden = false; this.view.show(); }; TimeControl.prototype.reset = function () { this._setDurationTime(0); this._setCurrentTime(0); this.view.showDuration(); this.view.setCurrentTimeBackward(false); this.show(); }; TimeControl.prototype.destroy = function () { this._stopIntervalUpdates(); this._unbindEvents(); this.view.destroy(); }; TimeControl.moduleName = 'timeControl'; TimeControl.View = time_view_1.default; TimeControl.dependencies = ['engine', 'eventEmitter', 'theme']; return TimeControl; }()); exports.default = TimeControl; //# sourceMappingURL=time.js.map