From 0f64b1ad2f7d1527737fc2f1fbbb69890dd9a77a Mon Sep 17 00:00:00 2001 From: voyage200 Date: Fri, 13 Dec 2024 00:35:28 +0800 Subject: [PATCH] Lily/Video bundle hls.js directly into the extension --- extensions/Lily/Video.js | 102 ++++++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 39 deletions(-) diff --git a/extensions/Lily/Video.js b/extensions/Lily/Video.js index 932b9413fe..66e4361115 100644 --- a/extensions/Lily/Video.js +++ b/extensions/Lily/Video.js @@ -45,11 +45,30 @@ this.videoError = false; - this.readyPromise = new Promise((resolve) => { + this.videoElement = document.createElement("video"); + + this.readyPromise = new Promise(async (resolve) => { this.readyCallback = resolve; + if ( + videoSrc.endsWith(".m3u8") && + !this.videoElement.canPlayType("application/vnd.apple.mpegurl") + ) { + // try use hls.js for m3u8 + await this.loadHlsJsIfNeeded(); + // @ts-ignore + const Hls = window.Hls; + if (Hls.isSupported()) { + this.hls = new Hls(); + this.hls.loadSource(videoSrc); + this.hls.attachMedia(this.videoElement); + } else { + this.videoElement.src = videoSrc; + } + } else { + this.videoElement.src = videoSrc; + } }); - this.videoElement = document.createElement("video"); // Need to set non-zero dimensions, otherwise scratch-render thinks this is an empty image this.videoElement.width = 1; this.videoElement.height = 1; @@ -65,26 +84,6 @@ this.markVideoDirty(); }; - if ( - videoSrc.endsWith(".m3u8") && - !this.videoElement.canPlayType("application/vnd.apple.mpegurl") - ) { - // try use hls.js for m3u8 - this.loadHlsJsIfNeeded(() => { - // @ts-ignore - const Hls = window.Hls; - if (Hls.isSupported()) { - this.hls = new Hls(); - this.hls.loadSource(videoSrc); - this.hls.attachMedia(this.videoElement); - } else { - this.videoElement.src = videoSrc; - } - }); - } else { - this.videoElement.src = videoSrc; - } - this.videoElement.currentTime = 0; //