UNPKG

playable

Version:

Video player based on HTML5Video

97 lines 3.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var constants_1 = require("../../../constants"); var player_api_decorator_1 = (0, tslib_1.__importDefault)(require("../../../core/player-api-decorator")); var loading_cover_view_1 = (0, tslib_1.__importDefault)(require("./loading-cover.view")); var LoadingCover = /** @class */ (function () { function LoadingCover(_a) { var eventEmitter = _a.eventEmitter, engine = _a.engine, bottomBlock = _a.bottomBlock, rootContainer = _a.rootContainer; this._eventEmitter = eventEmitter; this.isHidden = false; this._engine = engine; this._bottomBlock = bottomBlock; this.show = this.show.bind(this); this.hide = this.hide.bind(this); this._initUI(); this._bindEvents(); rootContainer.appendComponentElement(this.getElement()); this.hide(); } LoadingCover.prototype.getElement = function () { return this.view.getElement(); }; LoadingCover.prototype._bindEvents = function () { this._unbindEvents = this._eventEmitter.bindEvents([ [constants_1.VideoEvent.STATE_CHANGED, this._checkForWaitingState], [constants_1.VideoEvent.UPLOAD_SUSPEND, this.hide], ], this); }; LoadingCover.prototype._checkForWaitingState = function (_a) { var nextState = _a.nextState; switch (nextState) { case constants_1.EngineState.LOAD_STARTED: if (this._engine.isPreloadActive) { this.show(); } break; case constants_1.EngineState.WAITING: if (!this._engine.isMetadataLoaded) { this.show(); } break; case constants_1.EngineState.READY_TO_PLAY: this.hide(); break; /* ignore coverage */ default: break; } }; LoadingCover.prototype._initUI = function () { this.view = new loading_cover_view_1.default(); }; LoadingCover.prototype.hide = function () { if (!this.isHidden) { this._eventEmitter.emitAsync(constants_1.UIEvent.LOADING_COVER_HIDE); this.view.hide(); this.isHidden = true; } }; LoadingCover.prototype.show = function () { if (this.isHidden) { this._bottomBlock.hideContent(); this._eventEmitter.emitAsync(constants_1.UIEvent.LOADING_COVER_SHOW); this.view.show(); this.isHidden = false; } }; /** * Method for setting source of image, that would be used as loading cover instead of loader. * @param src - Link to your image * @example * player.setLoadingCover('https://example.com/cover.png'); * */ LoadingCover.prototype.setLoadingCover = function (src) { this.view.setCover(src); }; LoadingCover.prototype.destroy = function () { this._unbindEvents(); this.view.destroy(); }; LoadingCover.moduleName = 'loadingCover'; LoadingCover.View = loading_cover_view_1.default; LoadingCover.dependencies = [ 'engine', 'eventEmitter', 'bottomBlock', 'rootContainer', ]; (0, tslib_1.__decorate)([ (0, player_api_decorator_1.default)() ], LoadingCover.prototype, "setLoadingCover", null); return LoadingCover; }()); exports.default = LoadingCover; //# sourceMappingURL=loading-cover.js.map