1/** Requests an initial frame without playing or replacing the video's streaming source. */
2export function prepareVideoFirstFrame(
3 video: Pick<
4 HTMLVideoElement,
5 "autoplay" | "currentTime" | "duration" | "paused" | "played" | "seeking" | "src"
6 >,
7): void {
8 if (
9 video.autoplay ||
10 !video.paused ||
11 video.seeking ||
12 video.currentTime !== 0 ||
13 video.played.length > 0 ||
14 !Number.isFinite(video.duration) ||
15 video.duration <= 0
16 ) {
17 return;
18 }
19
20 const fragment = video.src.split("#", 2)[1];
21 if (fragment && new URLSearchParams(fragment).has("t")) return;
22
23 try {
24 video.currentTime = Math.min(0.1, video.duration / 2);
25 } catch {
26 // A rejected preview seek must leave the native Play control usable.
27 }
28}