From 3d3b587a9c893278459da88846f1e94c1cb49f93 Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Sat, 10 Jul 2021 02:25:09 +0530 Subject: [PATCH] Load shaka-player as soon as Player component is loaded. --- src/components/Player.vue | 44 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/components/Player.vue b/src/components/Player.vue index 906a8bd4..97667557 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -39,6 +39,9 @@ export default { return _this.getPreferenceBoolean("playerAutoPlay", true); }, }, + mounted() { + if (!this.shaka) this.shakaPromise = shaka.then(shaka => shaka.default).then(shaka => (this.shaka = shaka)); + }, methods: { loadVideo() { const component = this; @@ -73,31 +76,28 @@ export default { } if (noPrevPlayer) - shaka - .then(shaka => shaka.default) - .then(shaka => { - this.shaka = shaka; - shaka.polyfill.installAll(); + this.shakaPromise.then(() => { + this.shaka.polyfill.installAll(); - const localPlayer = new shaka.Player(videoEl); + const localPlayer = new this.shaka.Player(videoEl); - localPlayer.getNetworkingEngine().registerRequestFilter((_type, request) => { - const uri = request.uris[0]; - var url = new URL(uri); - if (url.host.endsWith(".googlevideo.com")) { - url.searchParams.set("host", url.host); - url.host = new URL(component.video.proxyUrl).host; - request.uris[0] = url.toString(); - } - }); - - localPlayer.configure( - "streaming.bufferingGoal", - Math.max(this.getPreferenceNumber("bufferGoal", 10), 10), - ); - - this.setPlayerAttrs(localPlayer, videoEl, uri, shaka); + localPlayer.getNetworkingEngine().registerRequestFilter((_type, request) => { + const uri = request.uris[0]; + var url = new URL(uri); + if (url.host.endsWith(".googlevideo.com")) { + url.searchParams.set("host", url.host); + url.host = new URL(component.video.proxyUrl).host; + request.uris[0] = url.toString(); + } }); + + localPlayer.configure( + "streaming.bufferingGoal", + Math.max(this.getPreferenceNumber("bufferGoal", 10), 10), + ); + + this.setPlayerAttrs(localPlayer, videoEl, uri, this.shaka); + }); else this.setPlayerAttrs(this.player, videoEl, uri, this.shaka); if (noPrevPlayer) {