vycxexra8: Play feed videos from hlsUrl with a thumbnail fallback

This commit is contained in:
2026-10-19 14:03:12 -06:00
parent 18e0386a99
commit 69e3c1ba2f
8 changed files with 178 additions and 2 deletions
+21
View File
@@ -0,0 +1,21 @@
// Chooses how a feed video plays. Pure, so it is unit-testable without a browser.
export type Playback = "none" | "native" | "hlsjs";
export interface PlaybackEnv {
/** True when the browser can play .m3u8 directly (Safari). */
nativeHls: boolean;
/** True when hls.js (Media Source Extensions) is supported. */
hlsJsSupported: boolean;
}
/** No hlsUrl: thumbnail only. Native HLS wins; hls.js is the fallback. */
export function choosePlayback(hlsUrl: string | null | undefined, env: PlaybackEnv): Playback {
if (!hlsUrl) return "none";
if (env.nativeHls) return "native";
return env.hlsJsSupported ? "hlsjs" : "none";
}
export function supportsNativeHls(video: Pick<HTMLVideoElement, "canPlayType">): boolean {
return video.canPlayType("application/vnd.apple.mpegurl") !== "";
}