+ {/* Left Side: Play, Vol, Time */}
+
+
-
-
-
handleVolumeChange(v[0])}
- max={1}
- step={0.05}
- />
+
+
+
+
+
+
+
+ handleVolumeChange(v[0])}
+ max={1}
+ step={0.05}
+ />
+
+
+
+
+ {displayString}
+
+
+
+
+
+
+
+ Format
+
+ setVideoTimeDisplayMode('standard')}
+ className="flex items-center justify-between cursor-pointer text-xs"
+ >
+ Standard Time
+ {videoTimeDisplayMode === 'standard' && (
+
+ )}
+
+ setVideoTimeDisplayMode('frames')}
+ className="flex items-center justify-between cursor-pointer text-xs"
+ >
+ Frames
+ {videoTimeDisplayMode === 'frames' && (
+
+ )}
+
+ setVideoTimeDisplayMode('timecode')}
+ className="flex items-center justify-between cursor-pointer text-xs"
+ >
+ Timecode
+ {videoTimeDisplayMode === 'timecode' && (
+
+ )}
+
+
+
+
-
-
- {displayString}
-
-
-
-
-
-
-
- Format
-
- setVideoTimeDisplayMode('standard')}
- className="flex items-center justify-between cursor-pointer text-xs"
- >
- Standard Time
- {videoTimeDisplayMode === 'standard' && (
-
- )}
-
- setVideoTimeDisplayMode('frames')}
- className="flex items-center justify-between cursor-pointer text-xs"
- >
- Frames
- {videoTimeDisplayMode === 'frames' && (
-
- )}
-
- setVideoTimeDisplayMode('timecode')}
- className="flex items-center justify-between cursor-pointer text-xs"
- >
- Timecode
- {videoTimeDisplayMode === 'timecode' && (
-
- )}
-
-
-
-
-
-
- {/* Right Side: Zoom, Speed, Res, Download, Fullscreen */}
-
- {/* Zoom Controls */}
- {!isAudio && (
-
-
+ {/* Right Side: Zoom, Speed, Res, Download, Fullscreen */}
+
+ {/* Zoom Controls */}
+ {!isAudio && (
+
+
+
+
+ {Math.round(zoom * 100)}%
+
+
+
-
- {Math.round(zoom * 100)}%
-
-
-
-
- )}
+ )}
- {/* Playback Rate */}
-
-
-
-
-
- {[0.5, 1, 1.5, 2].map((rate) => (
- changePlaybackRate(rate)}
- className={cn(
- 'rounded py-1 px-2 text-left text-xs',
- state.playbackRate === rate
- ? 'bg-primary text-primary-foreground focus:bg-primary focus:text-primary-foreground'
- : 'text-foreground',
- )}
- >
- {rate}x
-
- ))}
-
-
-
- {/* Settings / Resolution */}
- {!isAudio && resolutions.length > 0 && (
+ {/* Playback Rate */}
-
-
- {m.quality()}
- {data.media?.isHls && (
+ {[0.5, 1, 1.5, 2].map((rate) => (
- changeResolution({
- resolution: 'Auto',
- width: data.media?.metadata?.originalWidth ?? 0,
- height: data.media?.metadata?.originalHeight ?? 0,
- } as DisplayTranscode)
- }
+ key={rate}
+ onClick={() => changePlaybackRate(rate)}
className={cn(
- 'flex w-full items-center justify-between cursor-pointer',
- state.currentResolution === 'Auto'
- ? 'text-primary font-medium'
+ 'rounded py-1 px-2 text-left text-xs',
+ state.playbackRate === rate
+ ? 'bg-primary text-primary-foreground focus:bg-primary focus:text-primary-foreground'
: 'text-foreground',
)}
>
- {m.quality_auto()}
+ {rate}x
- )}
- {resolutions.map((res) => {
- const itemKey = `${res.resolution}-${res.hdr ? 'hdr' : 'sdr'}`
- const isSelected =
- state.currentResolution === res.resolution &&
- Boolean(state.isCurrentHdr) === Boolean(res.hdr)
- const isManualDisabled =
- Boolean(data.media?.isHls) && state.isHlsManualSupported === false
- return (
- !isManualDisabled && changeResolution(res)}
- className={cn(
- 'flex w-full items-center justify-between',
- isSelected ? 'text-primary font-medium' : 'text-foreground',
- isManualDisabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer',
- )}
- >
-
- {res.resolution === 'Original' ? m.original() : res.resolution}
- {res.hdr && (
-
- {m.hdr()}
-
- )}
-
-
- {res.width}x{res.height}
-
-
- )
- })}
+ ))}
- )}
- {/* Download */}
- {allowDownload &&
- (isAudio ? (
-
handleDownload(data.media?.original?.key || '')}
- className="transition-colors hover:text-primary"
- title={m.download()}
- disabled={!data.media?.original?.key}
- >
-
-
- ) : (
+ {/* Settings / Resolution */}
+ {!isAudio && resolutions.length > 0 && (
-
-
+
+
+
+
+ {state.currentResolution === 'Auto'
+ ? state.activeAutoResolution
+ ? `${m.quality_auto()} (${state.activeAutoResolution})`
+ : m.quality_auto()
+ : state.currentResolution === 'Original'
+ ? m.original()
+ : state.currentResolution}
+
+ {state.isCurrentHdr && (
+
+ {m.hdr()}
+
+ )}
+
+
- {m.download()}
- {(data.media?.videoTranscodes && data.media.videoTranscodes.length > 0
- ? data.media.videoTranscodes
- : resolutions
- ).map((res) => {
- const resLabel = getVideoResolutionLabel(res)
- const itemKey = res.key || `${resLabel}-${res.hdr ? 'hdr' : 'sdr'}`
+ {m.quality()}
+ {data.media?.isHls && (
+
+ changeResolution({
+ resolution: 'Auto',
+ width: data.media?.metadata?.originalWidth ?? 0,
+ height: data.media?.metadata?.originalHeight ?? 0,
+ } as DisplayTranscode)
+ }
+ className={cn(
+ 'flex w-full items-center justify-between cursor-pointer',
+ state.currentResolution === 'Auto'
+ ? 'text-primary font-medium'
+ : 'text-foreground',
+ )}
+ >
+ {m.quality_auto()}
+
+ )}
+ {resolutions.map((res) => {
+ const itemKey = `${res.resolution}-${res.hdr ? 'hdr' : 'sdr'}`
+ const isSelected =
+ state.currentResolution === res.resolution &&
+ Boolean(state.isCurrentHdr) === Boolean(res.hdr)
+ const isManualDisabled =
+ Boolean(data.media?.isHls) && state.isHlsManualSupported === false
return (
handleDownload(res.key ?? '')}
- className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground cursor-pointer"
+ disabled={isManualDisabled}
+ onClick={() => !isManualDisabled && changeResolution(res)}
+ className={cn(
+ 'flex w-full items-center justify-between',
+ isSelected ? 'text-primary font-medium' : 'text-foreground',
+ isManualDisabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer',
+ )}
>
- {resLabel}
+
+ {res.resolution === 'Original' ? m.original() : res.resolution}
+
{res.hdr && (
{m.hdr()}
)}
- MP4
+
+ {res.width}x{res.height}
+
)
})}
- {data.media?.original?.key && (
- <>
-
- handleDownload(data.media?.original?.key ?? '')}
- className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
- >
- {m.original()}
-
- {data.name?.split('.').pop()?.toUpperCase() || 'RAW'}
-
-
- >
- )}
- ))}
-
- {/* Fullscreen */}
-
- {state.isFullScreen ? (
-
- ) : (
-
)}
-
+
+ {/* Download */}
+ {allowDownload &&
+ (isAudio ? (
+
handleDownload(data.media?.original?.key || '')}
+ className="transition-colors hover:text-primary"
+ title={m.download()}
+ disabled={!data.media?.original?.key}
+ >
+
+
+ ) : (
+
+
+
+
+
+
+
+ {m.download()}
+ {(data.media?.videoTranscodes && data.media.videoTranscodes.length > 0
+ ? data.media.videoTranscodes
+ : resolutions
+ ).map((res) => {
+ const resLabel = getVideoResolutionLabel(res)
+ const itemKey = res.key || `${resLabel}-${res.hdr ? 'hdr' : 'sdr'}`
+ return (
+ handleDownload(res.key ?? '')}
+ className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground cursor-pointer"
+ >
+
+ {resLabel}
+ {res.hdr && (
+
+ {m.hdr()}
+
+ )}
+
+ MP4
+
+ )
+ })}
+ {data.media?.original?.key && (
+ <>
+
+ handleDownload(data.media?.original?.key ?? '')}
+ className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
+ >
+ {m.original()}
+
+ {data.name?.split('.').pop()?.toUpperCase() || 'RAW'}
+
+
+ >
+ )}
+
+
+ ))}
+
+ {/* Fullscreen */}
+
+ {state.isFullScreen ? (
+
+ ) : (
+
+ )}
+
+
diff --git a/packages/webui/components/viewers/video/video-viewer.test.tsx b/packages/webui/components/viewers/video/video-viewer.test.tsx
index 394fb85d..04d685b0 100644
--- a/packages/webui/components/viewers/video/video-viewer.test.tsx
+++ b/packages/webui/components/viewers/video/video-viewer.test.tsx
@@ -566,4 +566,229 @@ describe('VideoViewer', () => {
expect(settingsButton?.textContent).toContain('1080p')
expect(settingsButton?.textContent).not.toContain('1920p')
})
+
+ it('sets poster on video element from file.preview.thumbnailUrl', () => {
+ const videoWithThumb: AssetInfo = {
+ id: 'video-thumb',
+ name: 'thumb.mp4',
+ proxyType: 'video',
+ preview: {
+ thumbnailUrl: 'https://cdn.example.com/poster.jpg',
+ },
+ media: {
+ metadata: {
+ originalWidth: 1920,
+ originalHeight: 1080,
+ duration: 10,
+ frameRate: 30,
+ totalFrames: 300,
+ },
+ videoTranscodes: [
+ {
+ resolution: '1080p',
+ url: 'https://cdn.example.com/video-1080p.mp4',
+ width: 1920,
+ height: 1080,
+ },
+ ],
+ },
+ } as unknown as AssetInfo
+
+ const { container } = render(
)
+ const video = container.querySelector('[data-testid="video-area"] video') as HTMLVideoElement
+ expect(video.getAttribute('poster')).toBe('https://cdn.example.com/poster.jpg')
+ })
+
+ it('shows loading spinner initially and transitions to play overlay on loadeddata', () => {
+ const testVideo: AssetInfo = {
+ id: 'video-loading-test',
+ name: 'loading.mp4',
+ proxyType: 'video',
+ media: {
+ metadata: {
+ originalWidth: 1920,
+ originalHeight: 1080,
+ duration: 10,
+ frameRate: 30,
+ totalFrames: 300,
+ },
+ videoTranscodes: [
+ {
+ resolution: '1080p',
+ url: 'https://cdn.example.com/video-1080p.mp4',
+ width: 1920,
+ height: 1080,
+ },
+ ],
+ },
+ } as unknown as AssetInfo
+
+ const { container } = render(
)
+ const video = container.querySelector('[data-testid="video-area"] video') as HTMLVideoElement
+
+ // 1. Initially loading spinner is visible, play overlay is not
+ expect(container.querySelector('[data-testid="video-loading-spinner"]')).not.toBeNull()
+ expect(container.querySelector('[data-testid="video-play-overlay"]')).toBeNull()
+
+ // 2. Control bar inner wrapper is dimmed & non-interactive
+ const controlBarWrapper = container.querySelector('.pointer-events-none.opacity-60')
+ expect(controlBarWrapper).not.toBeNull()
+
+ // 3. Dispatch loadeddata
+ act(() => {
+ video.dispatchEvent(new Event('loadeddata'))
+ })
+
+ // Spinner is gone, play overlay is visible, controls are interactive
+ expect(container.querySelector('[data-testid="video-loading-spinner"]')).toBeNull()
+ expect(container.querySelector('[data-testid="video-play-overlay"]')).not.toBeNull()
+ expect(container.querySelector('.pointer-events-none.opacity-60')).toBeNull()
+ })
+
+ it('debounces waiting stall with 200ms delay and cancels spinner on quick recovery', () => {
+ vi.useFakeTimers()
+ try {
+ const testVideo: AssetInfo = {
+ id: 'video-stall-test',
+ name: 'stall.mp4',
+ proxyType: 'video',
+ media: {
+ metadata: {
+ originalWidth: 1920,
+ originalHeight: 1080,
+ duration: 10,
+ frameRate: 30,
+ totalFrames: 300,
+ },
+ videoTranscodes: [
+ {
+ resolution: '1080p',
+ url: 'https://cdn.example.com/video-1080p.mp4',
+ width: 1920,
+ height: 1080,
+ },
+ ],
+ },
+ } as unknown as AssetInfo
+
+ const { container } = render(
)
+ const video = container.querySelector('[data-testid="video-area"] video') as HTMLVideoElement
+
+ // Become ready first
+ act(() => {
+ video.dispatchEvent(new Event('loadeddata'))
+ })
+ expect(container.querySelector('[data-testid="video-loading-spinner"]')).toBeNull()
+
+ // Stalls briefly (<200ms)
+ act(() => {
+ video.dispatchEvent(new Event('waiting'))
+ })
+ // Immediately after waiting, spinner should NOT be shown yet (debounced)
+ expect(container.querySelector('[data-testid="video-loading-spinner"]')).toBeNull()
+
+ // Recovers quickly at 100ms
+ act(() => {
+ vi.advanceTimersByTime(100)
+ video.dispatchEvent(new Event('playing'))
+ })
+ act(() => {
+ vi.advanceTimersByTime(150)
+ })
+ // Spinner still not shown
+ expect(container.querySelector('[data-testid="video-loading-spinner"]')).toBeNull()
+
+ // Now a long stall (>200ms)
+ act(() => {
+ video.dispatchEvent(new Event('waiting'))
+ })
+ act(() => {
+ vi.advanceTimersByTime(250)
+ })
+ // Spinner should now appear!
+ expect(container.querySelector('[data-testid="video-loading-spinner"]')).not.toBeNull()
+
+ // Resume playing
+ act(() => {
+ video.dispatchEvent(new Event('playing'))
+ })
+ expect(container.querySelector('[data-testid="video-loading-spinner"]')).toBeNull()
+ } finally {
+ vi.useRealTimers()
+ }
+ })
+
+ it('does not cancel waiting stall debounce when progress events fire during stall', () => {
+ vi.useFakeTimers()
+ try {
+ const testVideo: AssetInfo = {
+ id: 'video-stall-progress-test',
+ name: 'stall-progress.mp4',
+ proxyType: 'video',
+ media: {
+ metadata: {
+ originalWidth: 1920,
+ originalHeight: 1080,
+ duration: 10,
+ frameRate: 30,
+ totalFrames: 300,
+ },
+ videoTranscodes: [
+ {
+ resolution: '1080p',
+ url: 'https://cdn.example.com/video-1080p.mp4',
+ width: 1920,
+ height: 1080,
+ },
+ ],
+ },
+ } as unknown as AssetInfo
+
+ const { container } = render(
)
+ const video = container.querySelector('[data-testid="video-area"] video') as HTMLVideoElement
+
+ // 1. Initial ready state
+ act(() => {
+ video.dispatchEvent(new Event('loadeddata'))
+ })
+ expect(container.querySelector('[data-testid="video-loading-spinner"]')).toBeNull()
+
+ // 2. Play starts (paused === false)
+ Object.defineProperty(video, 'paused', { value: false, configurable: true, writable: true })
+ act(() => {
+ video.dispatchEvent(new Event('playing'))
+ })
+
+ // 3. Stalls: dispatches waiting
+ act(() => {
+ video.dispatchEvent(new Event('waiting'))
+ })
+ // Spinner not visible immediately (within 200ms debounce)
+ expect(container.querySelector('[data-testid="video-loading-spinner"]')).toBeNull()
+
+ // 4. Progress event fires at 100ms while paused is false (data still trickling in)
+ act(() => {
+ vi.advanceTimersByTime(100)
+ video.dispatchEvent(new Event('progress'))
+ })
+ // Should NOT clear debounce or mark loading false
+ expect(container.querySelector('[data-testid="video-loading-spinner"]')).toBeNull()
+
+ // 5. Advance past 200ms debounce (advance remaining 110ms)
+ act(() => {
+ vi.advanceTimersByTime(110)
+ })
+ // Spinner should now appear despite the progress event!
+ expect(container.querySelector('[data-testid="video-loading-spinner"]')).not.toBeNull()
+
+ // 6. Playback resumes: dispatch playing
+ act(() => {
+ video.dispatchEvent(new Event('playing'))
+ })
+ // Spinner disappears
+ expect(container.querySelector('[data-testid="video-loading-spinner"]')).toBeNull()
+ } finally {
+ vi.useRealTimers()
+ }
+ })
})
diff --git a/packages/webui/components/viewers/video/video-viewer.tsx b/packages/webui/components/viewers/video/video-viewer.tsx
index cb62faaf..d9ea1235 100644
--- a/packages/webui/components/viewers/video/video-viewer.tsx
+++ b/packages/webui/components/viewers/video/video-viewer.tsx
@@ -1,6 +1,6 @@
import { client } from '@/ui/api/client'
import { cn } from '@/ui/lib/utils'
-import { Play, AudioLines } from 'lucide-react'
+import { Play, AudioLines, Loader2 } from 'lucide-react'
import React, { useCallback, useEffect, useRef, useState, useImperativeHandle } from 'react'
import Hls from 'hls.js'
import { useFramePlayer } from './use-frame-player'
@@ -157,7 +157,12 @@ const VideoViewer = React.forwardRef
(
}))
setActiveAutoResolution(undefined)
setHasManuallyZoomed(false)
+ if (waitingTimeoutRef.current) {
+ clearTimeout(waitingTimeoutRef.current)
+ waitingTimeoutRef.current = null
+ }
setIsPlayerReady(false)
+ setIsLoading(true)
setBuffered(0)
lastProcessedStartTimeRef.current = null
setHasStartedPlaying(false)
@@ -250,6 +255,8 @@ const VideoViewer = React.forwardRef(
const [buffered, setBuffered] = useState(0)
const [isControlsVisible, setIsControlsVisible] = useState(true)
const [isPlayerReady, setIsPlayerReady] = useState(false)
+ const [isLoading, setIsLoading] = useState(true)
+ const waitingTimeoutRef = useRef | null>(null)
const lastProcessedStartTimeRef = useRef(null)
// Frame-accurate hook and derived state
@@ -285,6 +292,7 @@ const VideoViewer = React.forwardRef(
progress,
activeAutoResolution,
isHlsManualSupported,
+ isLoading,
}
// Trigger time update event reactively
@@ -309,7 +317,12 @@ const VideoViewer = React.forwardRef(
hlsRef.current = null
}
+ if (waitingTimeoutRef.current) {
+ clearTimeout(waitingTimeoutRef.current)
+ waitingTimeoutRef.current = null
+ }
setIsPlayerReady(false)
+ setIsLoading(true)
setActiveAutoResolution(undefined)
const startAutoPlay = () => {
@@ -339,7 +352,6 @@ const VideoViewer = React.forwardRef(
hls.loadSource(targetSrc)
hls.on(Hls.Events.MANIFEST_PARSED, () => {
- setIsPlayerReady(true)
if (autoPlay) {
if (video.readyState >= 2) {
startAutoPlay()
@@ -406,7 +418,17 @@ const VideoViewer = React.forwardRef(
}
}
+ const clearWaitingTimeout = () => {
+ if (waitingTimeoutRef.current) {
+ clearTimeout(waitingTimeoutRef.current)
+ waitingTimeoutRef.current = null
+ }
+ }
+
const handlePlay = () => {
+ clearWaitingTimeout()
+ setIsLoading(false)
+ setIsPlayerReady(true)
if (pendingResolutionCorrectionRef.current) {
pendingResolutionCorrectionRef.current()
pendingResolutionCorrectionRef.current = null
@@ -420,12 +442,33 @@ const VideoViewer = React.forwardRef(
onPause?.()
}
const handleEnded = () => {
+ clearWaitingTimeout()
+ setIsLoading(false)
setState((p) => ({ ...p, isPlaying: false }))
}
- const handleLoadedMetadata = () => {
+ const handleLoadedData = () => {
+ clearWaitingTimeout()
+ setIsLoading(false)
setIsPlayerReady(true)
}
+ const handleCanPlay = () => {
+ clearWaitingTimeout()
+ setIsLoading(false)
+ setIsPlayerReady(true)
+ }
+ const handlePlaying = () => {
+ clearWaitingTimeout()
+ setIsLoading(false)
+ }
+ const handleWaiting = () => {
+ clearWaitingTimeout()
+ waitingTimeoutRef.current = setTimeout(() => {
+ setIsLoading(true)
+ }, 200)
+ }
const handleLoadStart = () => {
+ clearWaitingTimeout()
+ setIsLoading(true)
setIsPlayerReady(false)
}
const handleProgress = () => {
@@ -461,13 +504,23 @@ const VideoViewer = React.forwardRef(
}))
}
const handleError = () => {
+ clearWaitingTimeout()
+ setIsLoading(false)
console.error('Video Error:', video.error)
}
+ if (video.readyState >= 2) {
+ setIsLoading(false)
+ setIsPlayerReady(true)
+ }
+
video.addEventListener('play', handlePlay)
video.addEventListener('pause', handlePause)
video.addEventListener('ended', handleEnded)
- video.addEventListener('loadedmetadata', handleLoadedMetadata)
+ video.addEventListener('loadeddata', handleLoadedData)
+ video.addEventListener('canplay', handleCanPlay)
+ video.addEventListener('playing', handlePlaying)
+ video.addEventListener('waiting', handleWaiting)
video.addEventListener('loadstart', handleLoadStart)
video.addEventListener('timeupdate', handleProgress)
video.addEventListener('progress', handleProgress)
@@ -480,10 +533,14 @@ const VideoViewer = React.forwardRef(
// Cleanup
return () => {
+ clearWaitingTimeout()
video.removeEventListener('play', handlePlay)
video.removeEventListener('pause', handlePause)
video.removeEventListener('ended', handleEnded)
- video.removeEventListener('loadedmetadata', handleLoadedMetadata)
+ video.removeEventListener('loadeddata', handleLoadedData)
+ video.removeEventListener('canplay', handleCanPlay)
+ video.removeEventListener('playing', handlePlaying)
+ video.removeEventListener('waiting', handleWaiting)
video.removeEventListener('loadstart', handleLoadStart)
video.removeEventListener('timeupdate', handleProgress)
video.removeEventListener('progress', handleProgress)
@@ -570,6 +627,7 @@ const VideoViewer = React.forwardRef(
// -- Event Handlers --
const togglePlay = useCallback(() => {
+ if (isLoading) return
// Disable click-to-play if drawing
if (useAnnotationStore.getState().isDrawing) return
@@ -593,7 +651,7 @@ const VideoViewer = React.forwardRef(
} else {
video.pause()
}
- }, [])
+ }, [isLoading])
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
@@ -949,6 +1007,7 @@ const VideoViewer = React.forwardRef(
className="w-full h-full block object-contain pointer-events-none"
playsInline
preload="auto"
+ poster={data.preview?.thumbnailUrl || undefined}
/>
)}
@@ -996,9 +1055,24 @@ const VideoViewer = React.forwardRef