vycxexra8: Play feed videos from hlsUrl with a thumbnail fallback
This commit is contained in:
@@ -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") !== "";
|
||||
}
|
||||
Reference in New Issue
Block a user