style: format static/player/video.ts

This commit is contained in:
2026-06-21 02:05:00 +02:00
committed by Milas Holsting
parent a602fa085b
commit 65d5d1774c

View File

@@ -1,4 +1,5 @@
import Hls from "hls.js"; import Hls from "hls.js";
import { attachHLSProfile } from "./hls_profile"; import { attachHLSProfile } from "./hls_profile";
import { state } from "./state"; import { state } from "./state";
import { absoluteTimeFromDisplay, displayTimeFromAbsolute, invalidateBounds } from "./timeline"; import { absoluteTimeFromDisplay, displayTimeFromAbsolute, invalidateBounds } from "./timeline";
@@ -21,10 +22,14 @@ export const destroyVideoSource = (): void => {
}; };
const shouldUseHLS = (type: string | undefined, url: string): boolean => { const shouldUseHLS = (type: string | undefined, url: string): boolean => {
if (type === "m3u8") return true; if (type === "m3u8") {
return true;
}
try { try {
const parsed = new URL(url, window.location.href); const parsed = new URL(url, window.location.href);
if (parsed.searchParams.get("hls") === "1") return true; if (parsed.searchParams.get("hls") === "1") {
return true;
}
return parsed.pathname.toLowerCase().endsWith(".m3u8"); return parsed.pathname.toLowerCase().endsWith(".m3u8");
} catch (error) { } catch (error) {
console.error("Failed to parse video URL:", error); console.error("Failed to parse video URL:", error);
@@ -35,11 +40,13 @@ const shouldUseHLS = (type: string | undefined, url: string): boolean => {
/** /**
* Force-loads a new video source and preserves playback position. * Force-loads a new video source and preserves playback position.
* *
* Some browsers can be flaky when switching between HLS URLs while playing. * Some browsers can be flaky when switching between HLS URLs while playing. Clearing `src` first
* Clearing `src` first ensures the media element fully resets before the new URL is set. * ensures the media element fully resets before the new URL is set.
*/ */
export const loadVideoSource = (url: string, type?: string, startTimeSeconds?: number): void => { export const loadVideoSource = (url: string, type?: string, startTimeSeconds?: number): void => {
if (!url) return; if (!url) {
return;
}
const wasPlaying = !state.elements.video.paused; const wasPlaying = !state.elements.video.paused;
const prevDisplayTime = displayTimeFromAbsolute(state.elements.video.currentTime); const prevDisplayTime = displayTimeFromAbsolute(state.elements.video.currentTime);