playable
Version:
Video player based on HTML5Video
304 lines • 10.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var types_1 = require("../../types");
var constants_1 = require("../../../../constants");
var state_engine_1 = (0, tslib_1.__importDefault)(require("./state-engine"));
var logger_1 = (0, tslib_1.__importDefault)(require("../../../../utils/logger"));
var get_mime_type_1 = require("../../../../utils/get-mime-type");
var NOT_IMPLEMENTED = 'Not available using chromecast';
var ChromecastOutput = /** @class */ (function () {
function ChromecastOutput(eventEmitter) {
this._eventEmitter = eventEmitter;
this._initRemote();
}
ChromecastOutput.prototype.play = function () {
if (this.isPaused) {
this._playerController.playOrPause();
}
return Promise.resolve();
};
ChromecastOutput.prototype.pause = function () {
if (!this.isPaused) {
this._playerController.playOrPause();
}
};
ChromecastOutput.prototype.setMute = function (mute) {
if (mute === undefined) {
return;
}
if (mute !== this.isMuted) {
this._playerController.muteOrUnmute();
}
};
ChromecastOutput.prototype.setAutoplay = function (isAutoplay) {
this._isAutoplay = isAutoplay;
};
ChromecastOutput.prototype.setInline = function () {
logger_1.default.warn(NOT_IMPLEMENTED);
};
ChromecastOutput.prototype.setCrossOrigin = function () {
logger_1.default.warn(NOT_IMPLEMENTED);
};
ChromecastOutput.prototype.setCurrentTime = function (time) {
this._player.currentTime = time;
this._playerController.seek();
};
ChromecastOutput.prototype.setVolume = function (volume) {
if (this._player.volumeLevel === volume) {
return;
}
this._player.volumeLevel = volume;
this._playerController.setVolumeLevel();
};
ChromecastOutput.prototype.setLoop = function () {
logger_1.default.warn(NOT_IMPLEMENTED);
};
ChromecastOutput.prototype.setPlaybackRate = function () {
// TODO: https://developers.google.com/cast/docs/reference/chrome/chrome.cast.media.Media#playbackRate
// Works only via receiver API
logger_1.default.warn(NOT_IMPLEMENTED);
};
ChromecastOutput.prototype.setPreload = function () {
logger_1.default.warn(NOT_IMPLEMENTED);
};
ChromecastOutput.prototype.setSrc = function (source, callback) {
var _this = this;
if (!source) {
callback();
return;
}
var cast = window.cast;
var chrome = window.chrome;
var calculatedSource = source;
var mimeType, url;
if (Array.isArray(source)) {
calculatedSource = source[0];
}
if (typeof calculatedSource === 'string') {
url = calculatedSource;
mimeType = (0, get_mime_type_1.getMimeByUrl)(calculatedSource);
}
else {
calculatedSource = calculatedSource;
mimeType = (0, get_mime_type_1.getMimeByType)(calculatedSource.type);
url = calculatedSource.url;
}
this._src = url;
var session = cast.framework.CastContext.getInstance().getCurrentSession();
var mediaInfo = new chrome.cast.media.MediaInfo(url, mimeType);
var request = new chrome.cast.media.LoadRequest(mediaInfo);
this._stateEngine.setState(constants_1.EngineState.SRC_SET);
session.loadMedia(request).then(function () {
_this._initRemote();
_this._stateEngine.setState(constants_1.EngineState.PLAYING);
if (typeof callback === 'function') {
callback();
}
});
};
ChromecastOutput.prototype._initRemote = function () {
var cast = window.cast;
this._player = new cast.framework.RemotePlayer();
this._playerController = new cast.framework.RemotePlayerController(this._player);
this._stateEngine = new state_engine_1.default(this._eventEmitter, this, this._playerController);
};
ChromecastOutput.prototype.getElement = function () {
logger_1.default.warn(NOT_IMPLEMENTED);
return null;
};
ChromecastOutput.prototype.getDebugInfo = function () {
return {
output: 'chromecast',
currentTime: this.currentTime,
duration: this.duration,
src: this.src,
};
};
Object.defineProperty(ChromecastOutput.prototype, "volume", {
get: function () {
return this._player.volumeLevel;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "currentTime", {
get: function () {
return this._player.currentTime;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "duration", {
get: function () {
return this._player.duration;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "autoplay", {
get: function () {
return this._isAutoplay;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "crossOrigin", {
get: function () {
logger_1.default.warn(NOT_IMPLEMENTED);
return 'anonymous';
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "playbackRate", {
get: function () {
return 1;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "buffered", {
get: function () {
return {
end: function () { return 0; },
start: function () { return 0; },
length: 0,
};
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "preload", {
get: function () {
return types_1.PreloadType.AUTO;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "isPaused", {
get: function () {
return this._player.isPaused;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "isMuted", {
get: function () {
return this._player.isMuted;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "isEnded", {
get: function () {
return this._stateEngine.state === constants_1.EngineState.ENDED;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "isInline", {
get: function () {
return false;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "isAutoplay", {
get: function () {
return this._isAutoplay;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "isSeekAvailable", {
get: function () {
return this._player.canSeek;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "isLoop", {
get: function () {
return false;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "isPreloadActive", {
get: function () {
return false;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "videoHeight", {
get: function () {
return 0;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "videoWidth", {
get: function () {
return 0;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "src", {
get: function () {
return this._src;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "currentState", {
get: function () {
return this._stateEngine.state;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "isAutoPlayActive", {
get: function () {
return false;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "isDynamicContent", {
get: function () {
return false;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "isDynamicContentEnded", {
get: function () {
return false;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "isMetadataLoaded", {
get: function () {
return true;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ChromecastOutput.prototype, "isSyncWithLive", {
get: function () {
return false;
},
enumerable: false,
configurable: true
});
ChromecastOutput.prototype.syncWithLive = function () {
logger_1.default.warn(NOT_IMPLEMENTED);
};
return ChromecastOutput;
}());
exports.default = ChromecastOutput;
//# sourceMappingURL=chromecast-output.js.map