feat(preview): inline video player via vidstack + hover-warm prefetch
Replace PreviewOverlay's bare <video controls> with a vidstack-driven player wrapping the same source URL. Vidstack's default video layout provides a polished chrome (gradient bottom bar, large play overlay, hover-revealed scrubber) and registers <media-player>/<media-provider> custom elements that vendor the browser quirks. To keep first-frame latency low, PhotoTile starts a hover-warm fetch of the playback URL after a short (120 ms) delay — a single Range request of the first 512 KB pages the backend's pre-transcoded MP4 cache file into the OS page cache and lands in the browser's HTTP cache, so when the player mounts and issues its own bytes=0- request the response is satisfied from disk. Each hash is warmed at most once per session; AbortController cancels hovers that don't commit. The vidstack modules are dynamically imported on mount so they never run during SvelteKit's static prerender — they side-effect customElements.define() calls which would crash under SSR.
This commit is contained in:
81
web/src/lib/components/preview/VideoPlayer.svelte
Normal file
81
web/src/lib/components/preview/VideoPlayer.svelte
Normal file
@@ -0,0 +1,81 @@
|
||||
<!--
|
||||
Vidstack-based video player. Wraps the native `<video>` element with a
|
||||
polished, PhotoPrism-style chrome (gradient bottom bar, large play
|
||||
overlay, hover-revealed scrubber). Element registration is dynamically
|
||||
imported so it never runs during SvelteKit's static prerender.
|
||||
|
||||
Imports are side-effecting:
|
||||
- `vidstack/player` registers <media-player> / <media-provider>
|
||||
- `vidstack/player/layouts/default` registers <media-video-layout>
|
||||
- the two CSS imports ship the dark theme and video-layout styles
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import 'vidstack/player/styles/default/theme.css';
|
||||
import 'vidstack/player/styles/default/layouts/video.css';
|
||||
|
||||
interface Props {
|
||||
src: string;
|
||||
poster?: string;
|
||||
title?: string;
|
||||
}
|
||||
let { src, poster, title }: Props = $props();
|
||||
|
||||
let ready = $state(false);
|
||||
|
||||
onMount(async () => {
|
||||
// Bundle these into the client chunk only — the modules side-effect
|
||||
// `customElements.define()` calls, which would crash under SSR.
|
||||
await import('vidstack/player');
|
||||
await import('vidstack/player/ui');
|
||||
await import('vidstack/player/layouts/default');
|
||||
ready = true;
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if ready}
|
||||
<!-- svelte-ignore element_invalid_self_closing_tag -->
|
||||
<media-player
|
||||
class="vds-player max-h-full max-w-full rounded-md shadow-2xl"
|
||||
title={title ?? ''}
|
||||
{src}
|
||||
{poster}
|
||||
autoplay
|
||||
muted
|
||||
playsinline
|
||||
load="eager"
|
||||
posterLoad="eager"
|
||||
crossorigin=""
|
||||
preferNativeHLS="false"
|
||||
streamType="on-demand"
|
||||
viewType="video"
|
||||
>
|
||||
<media-provider></media-provider>
|
||||
<media-video-layout></media-video-layout>
|
||||
</media-player>
|
||||
{:else}
|
||||
<!-- Fallback while the Vidstack module is loading. Keeps the poster
|
||||
visible so the transition into the full chrome isn't jarring. -->
|
||||
<!-- svelte-ignore a11y_media_has_caption -->
|
||||
<video
|
||||
{src}
|
||||
{poster}
|
||||
controls
|
||||
autoplay
|
||||
muted
|
||||
playsinline
|
||||
preload="auto"
|
||||
class="max-h-full max-w-full rounded-md object-contain shadow-2xl"
|
||||
></video>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
:global(.vds-player) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
aspect-ratio: auto;
|
||||
--media-brand: #3b82f6;
|
||||
--media-focus-ring-color: #3b82f6;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user