UNPKG

@awayjs/core

Version:
88 lines (87 loc) 3.2 kB
import { __extends } from "tslib"; import { EventDispatcher } from '../events/EventDispatcher'; import { EventBase } from '../events/EventBase'; var BaseAudioChannel = /** @class */ (function (_super) { __extends(BaseAudioChannel, _super); function BaseAudioChannel() { var _this = _super !== null && _super.apply(this, arguments) || this; _this._stopped = false; _this._loops = 0; _this._id = -1; _this._isLooping = false; _this._isPlaying = false; _this._isDecoding = false; return _this; } Object.defineProperty(BaseAudioChannel.prototype, "stopped", { get: function () { return this._stopped; }, enumerable: false, configurable: true }); BaseAudioChannel.prototype.isLooping = function () { return this._isLooping; }; BaseAudioChannel.prototype.isPlaying = function () { return this._isPlaying; }; BaseAudioChannel.prototype.isDecoding = function () { return this._isDecoding; }; BaseAudioChannel.prototype.play = function (buffer, offset, loop, id, meta) { this._loops = typeof loop === 'number' ? loop : loop ? 1000 : 0; this._id = id || -1; }; BaseAudioChannel.prototype.dispatchRestart = function () { this.dispatchEvent(BaseAudioChannel.RESTART_EVENT); }; /** * Check loop and try restart it * @protected */ BaseAudioChannel.prototype.tryRestartLoop = function () { this._loops--; if (this._loops <= 0) { return false; } if (this.restart()) { return true; } this._loops = 0; return false; }; BaseAudioChannel.prototype.completeInternally = function (dispatchComplete, tryRestart) { if (dispatchComplete === void 0) { dispatchComplete = true; } if (tryRestart === void 0) { tryRestart = true; } if (tryRestart && this.tryRestartLoop()) { return; } if (dispatchComplete) { this.dispatchEvent(BaseAudioChannel.COMPLETE_EVENT); } }; BaseAudioChannel.prototype.dispatchComplete = function () { this.dispatchEvent(BaseAudioChannel.COMPLETE_EVENT); }; BaseAudioChannel.prototype.dispatchStop = function (error) { if (error === void 0) { error = false; } this.dispatchEvent(error ? BaseAudioChannel.ERROR_EVENT : BaseAudioChannel.STOP_EVENT); // now channel can't be restarted; this.owner = null; this._stopped = true; this.removeAllEventListeners(); }; BaseAudioChannel.COMPLETE = 'complete'; BaseAudioChannel.RESTART = 'restart'; BaseAudioChannel.STOP = 'stop'; BaseAudioChannel.ERROR = 'error'; BaseAudioChannel.RESTART_EVENT = new EventBase(BaseAudioChannel.RESTART); BaseAudioChannel.COMPLETE_EVENT = new EventBase(BaseAudioChannel.COMPLETE); BaseAudioChannel.STOP_EVENT = new EventBase(BaseAudioChannel.STOP); BaseAudioChannel.ERROR_EVENT = new EventBase(BaseAudioChannel.ERROR); return BaseAudioChannel; }(EventDispatcher)); export { BaseAudioChannel };