|
|
|
@ -5,6 +5,7 @@ import { playerStatus } from "@/stores/player/slices/source";
@@ -5,6 +5,7 @@ import { playerStatus } from "@/stores/player/slices/source";
|
|
|
|
|
import { ThumbnailImage } from "@/stores/player/slices/thumbnails"; |
|
|
|
|
import { usePlayerStore } from "@/stores/player/store"; |
|
|
|
|
import { LoadableSource, selectQuality } from "@/stores/player/utils/qualities"; |
|
|
|
|
import { isSafari } from "@/utils/detectFeatures"; |
|
|
|
|
|
|
|
|
|
function makeQueue(layers: number): number[] { |
|
|
|
|
const output = [0, 1]; |
|
|
|
@ -39,7 +40,9 @@ class ThumnbnailWorker {
@@ -39,7 +40,9 @@ class ThumnbnailWorker {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
start(source: LoadableSource) { |
|
|
|
|
if (isSafari) return false; |
|
|
|
|
const el = document.createElement("video"); |
|
|
|
|
el.setAttribute("muted", "true"); |
|
|
|
|
const canvas = document.createElement("canvas"); |
|
|
|
|
this.hls = new Hls(); |
|
|
|
|
if (source.type === "mp4") { |
|
|
|
@ -76,9 +79,14 @@ class ThumnbnailWorker {
@@ -76,9 +79,14 @@ class ThumnbnailWorker {
|
|
|
|
|
|
|
|
|
|
private async takeSnapshot(at: number) { |
|
|
|
|
if (!this.videoEl || !this.canvasEl) return; |
|
|
|
|
await this.videoEl.play(); // so that `seeked` actually triggers
|
|
|
|
|
this.videoEl.currentTime = at; |
|
|
|
|
await new Promise((resolve) => { |
|
|
|
|
this.videoEl?.addEventListener("seeked", resolve); |
|
|
|
|
const onSeeked = () => { |
|
|
|
|
this.videoEl?.removeEventListener("seeked", onSeeked); |
|
|
|
|
resolve(null); |
|
|
|
|
}; |
|
|
|
|
this.videoEl?.addEventListener("seeked", onSeeked); |
|
|
|
|
}); |
|
|
|
|
if (!this.videoEl || !this.canvasEl) return; |
|
|
|
|
const ctx = this.canvasEl.getContext("2d"); |
|
|
|
@ -91,6 +99,7 @@ class ThumnbnailWorker {
@@ -91,6 +99,7 @@ class ThumnbnailWorker {
|
|
|
|
|
this.canvasEl.height |
|
|
|
|
); |
|
|
|
|
const imgUrl = this.canvasEl.toDataURL(); |
|
|
|
|
|
|
|
|
|
if (this.interrupted) return; |
|
|
|
|
if (imgUrl === "data:," || !imgUrl) return; // failed image rendering
|
|
|
|
|
|
|
|
|
@ -142,6 +151,7 @@ export function ThumbnailScraper() {
@@ -142,6 +151,7 @@ export function ThumbnailScraper() {
|
|
|
|
|
workerRef.current = ins; |
|
|
|
|
ins.start(inputStream.stream); |
|
|
|
|
}, [source, addImage, resetImages, status]); |
|
|
|
|
|
|
|
|
|
const startRef = useRef(start); |
|
|
|
|
useEffect(() => { |
|
|
|
|
startRef.current = start; |
|
|
|
|