diff --git a/packages/webui/components/compare/compare-control-bar.tsx b/packages/webui/components/compare/compare-control-bar.tsx
index 3e78e69a..c5e2a5f9 100644
--- a/packages/webui/components/compare/compare-control-bar.tsx
+++ b/packages/webui/components/compare/compare-control-bar.tsx
@@ -1,38 +1,17 @@
+import { ImageControlBar } from '@/ui/components/viewers/image-control-bar'
import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuLabel,
- DropdownMenuTrigger,
-} from '@/ui/components/ui/dropdown-menu'
-import { Slider } from '@/ui/components/ui/slider'
-import { cn } from '@/ui/lib/utils'
-import ProgressBar from '@/ui/components/viewers/progress-bar'
-import { formatTime, formatTimecode } from '@/ui/components/viewers/utils'
-import { useUiStore } from '@/ui/stores/ui'
-import type { MediaMetadata } from '@shumai/dtos'
-import {
- Download,
- Maximize,
- Minimize,
- Minus,
- Pause,
- Play,
- Plus,
- Repeat,
- Settings,
- Volume2,
- VolumeX,
-} from 'lucide-react'
+ VideoControlBar,
+ type DisplayTranscode,
+ type PlayerState,
+} from '@/ui/components/viewers/video-control-bar'
+import type { AssetInfo } from '@shumai/dtos'
+import { Maximize, Minimize } from 'lucide-react'
import type { PaneReportedState } from './types'
-const PLAYBACK_RATES = [0.5, 1, 1.5, 2]
-
interface CompareControlBarProps {
activeState: PaneReportedState | null
+ activeAsset: AssetInfo | null
previewUrl?: string
- metadata?: MediaMetadata
- startTimecode?: string | null
isFullScreen: boolean
onTogglePlay: () => void
onToggleLoop: () => void
@@ -50,9 +29,8 @@ interface CompareControlBarProps {
export function CompareControlBar({
activeState,
+ activeAsset,
previewUrl,
- metadata,
- startTimecode,
isFullScreen,
onTogglePlay,
onToggleLoop,
@@ -67,230 +45,83 @@ export function CompareControlBar({
onDownload,
onToggleFullScreen,
}: CompareControlBarProps) {
- const { videoTimeDisplayMode, setVideoTimeDisplayMode } = useUiStore()
+ // Active side is a video: reuse the shared VideoControlBar.
+ if (activeState?.kind === 'video' && activeState.video && activeAsset) {
+ const v = activeState.video
+ const duration = v.totalFrames / v.frameRate
+ const currentTime = v.currentFrame / v.frameRate
+ const state: PlayerState = {
+ isPlaying: v.isPlaying,
+ progress: duration > 0 ? (currentTime / duration) * 100 : 0,
+ currentTime,
+ duration,
+ volume: v.volume,
+ isMuted: v.isMuted,
+ isLooping: v.isLooping,
+ playbackRate: v.playbackRate,
+ isFullScreen,
+ showFrames: false,
+ currentResolution: v.currentResolution,
+ }
- const fullscreenButton = (
-
- )
+ // The active-side asset carries the metadata used for timecode display and
+ // preview scrubbing; ensure the preview url is present for the shared bar.
+ const data =
+ previewUrl && !activeAsset.media?.videoPreview
+ ? { ...activeAsset, media: { ...activeAsset.media, videoPreview: { url: previewUrl } } }
+ : activeAsset
- const zoomControls = (
-
-
-
- {Math.round((activeState?.zoom ?? 1) * 100)}%
-
-
-
-
- )
-
- // Image (or unsupported) control bar
- if (!activeState || activeState.kind !== 'video' || !activeState.video) {
return (
-
- {activeState?.kind === 'image' && zoomControls}
- {activeState?.kind === 'image' && (
-
- )}
- {fullscreenButton}
-
+ onChangeResolution(res.resolution)}
+ handleDownload={(key) => onDownload(key)}
+ toggleFullScreen={onToggleFullScreen}
+ onZoomChange={(nz) => (nz >= activeState.zoom ? onZoomIn() : onZoomOut())}
+ onZoomReset={onFit}
+ frameRate={v.frameRate}
+ totalFrames={v.totalFrames}
+ currentFrame={v.currentFrame}
+ seekToFrame={onSeek}
+ />
)
}
- const video = activeState.video
- const displayTotalFrames = Math.max(0, video.totalFrames - 1)
- const displayString =
- videoTimeDisplayMode === 'frames'
- ? `${video.currentFrame} / ${displayTotalFrames} fr`
- : videoTimeDisplayMode === 'standard'
- ? `${formatTimecode(video.currentFrame, video.frameRate, 'standard')} / ${formatTime(video.totalFrames / video.frameRate)}`
- : `${formatTimecode(video.currentFrame, video.frameRate, videoTimeDisplayMode, startTimecode)} / ${formatTimecode(displayTotalFrames, video.frameRate, videoTimeDisplayMode, startTimecode)}`
-
- const cycleTimeDisplay = () => {
- const modes: Array<'standard' | 'timecode' | 'frames'> = ['standard', 'timecode', 'frames']
- const idx = modes.indexOf(videoTimeDisplayMode as 'standard' | 'timecode' | 'frames')
- setVideoTimeDisplayMode(modes[(idx + 1) % modes.length])
+ // Active side is an image: reuse the shared ImageControlBar.
+ if (activeState?.kind === 'image') {
+ return (
+ onDownload()}
+ canDownload={!!activeAsset?.media?.original?.key}
+ fullscreen={{ isFullScreen, onToggle: onToggleFullScreen }}
+ />
+ )
}
- const previewResolutions = video.resolutions.filter((r) => !r.isRaw)
-
+ // Unsupported / not yet loaded: only expose fullscreen.
return (
-
-
-
-
-
-
-
- {/* Volume */}
-
-
- onVolumeChange(vals[0] ?? 0)}
- className="w-20"
- />
-
-
-
-
-
- {zoomControls}
-
- {/* Playback rate */}
-
-
- {video.playbackRate}x
-
-
- {PLAYBACK_RATES.map((rate) => (
- onChangePlaybackRate(rate)}
- className={cn(
- 'px-2 py-1 text-xs',
- video.playbackRate === rate
- ? 'bg-primary text-primary-foreground'
- : 'text-foreground',
- )}
- >
- {rate}x
-
- ))}
-
-
-
- {/* Resolution */}
- {previewResolutions.length > 0 && (
-
-
-
- {video.currentResolution}
-
-
- Quality
- {previewResolutions.map((res) => (
- onChangeResolution(res.resolution)}
- className={cn(
- 'flex w-full items-center justify-between',
- video.currentResolution === res.resolution
- ? 'font-medium text-primary'
- : 'text-foreground',
- )}
- >
- {res.resolution}
-
- {res.width}x{res.height}
-
-
- ))}
-
-
- )}
-
- {/* Download */}
-
-
-
-
-
- Download
- {video.resolutions.map((res) => (
- onDownload(res.key)}
- className="flex w-full items-center justify-between px-3 py-2 text-sm text-foreground"
- >
- {res.resolution}
- {res.isRaw ? 'RAW' : 'MP4'}
-
- ))}
-
-
-
- {fullscreenButton}
-
-
+
+
)
}
diff --git a/packages/webui/components/compare/compare-viewer.tsx b/packages/webui/components/compare/compare-viewer.tsx
index 89747c23..9c8daaff 100644
--- a/packages/webui/components/compare/compare-viewer.tsx
+++ b/packages/webui/components/compare/compare-viewer.tsx
@@ -334,9 +334,8 @@ export function CompareViewer({
{/* Zoom Toolbar */}
-
-
-
-
- {Math.round(zoom * 100)}%
-
-
-
-
-
-
-
+ handleZoom(1.2)}
+ onZoomOut={() => handleZoom(0.8)}
+ onFit={handleFit}
+ onDownload={handleDownload}
+ canDownload={!!file.media?.original?.key}
+ onCopy={handleCopy}
+ copied={copied}
+ canCopy={!!bestUrl}
+ />
>
)}
{isVideo && (
diff --git a/packages/webui/components/viewers/image-control-bar.tsx b/packages/webui/components/viewers/image-control-bar.tsx
new file mode 100644
index 00000000..d4d52c68
--- /dev/null
+++ b/packages/webui/components/viewers/image-control-bar.tsx
@@ -0,0 +1,87 @@
+import { Check, Copy, Download, Maximize, Minimize, Minus, Plus } from 'lucide-react'
+
+export interface ImageControlBarProps {
+ zoom: number
+ onZoomIn: () => void
+ onZoomOut: () => void
+ onFit: () => void
+ onDownload: () => void
+ canDownload: boolean
+ onCopy?: () => void
+ copied?: boolean
+ canCopy?: boolean
+ /** When provided, renders a fullscreen toggle (used by compare mode). */
+ fullscreen?: { isFullScreen: boolean; onToggle: () => void }
+}
+
+export function ImageControlBar({
+ zoom,
+ onZoomIn,
+ onZoomOut,
+ onFit,
+ onDownload,
+ canDownload,
+ onCopy,
+ copied = false,
+ canCopy = true,
+ fullscreen,
+}: ImageControlBarProps) {
+ return (
+
+
+
+
+ {Math.round(zoom * 100)}%
+
+
+
+
+ {onCopy && (
+
+ )}
+
+ {fullscreen && (
+
+ )}
+
+ )
+}
diff --git a/packages/webui/components/viewers/video-control-bar.tsx b/packages/webui/components/viewers/video-control-bar.tsx
new file mode 100644
index 00000000..238fcb14
--- /dev/null
+++ b/packages/webui/components/viewers/video-control-bar.tsx
@@ -0,0 +1,361 @@
+import { cn } from '@/ui/lib/utils'
+import { useUiStore } from '@/ui/stores/ui'
+import type { AssetInfo, VideoTranscode } from '@shumai/dtos'
+import {
+ Check,
+ ChevronDown,
+ Download,
+ Maximize,
+ Minimize,
+ Minus,
+ Pause,
+ Play,
+ Plus,
+ Repeat,
+ Settings,
+ Volume2,
+ VolumeX,
+} from 'lucide-react'
+import React from 'react'
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuTrigger,
+} from '../ui/dropdown-menu'
+import { Slider } from '../ui/slider'
+import ProgressBar from './progress-bar'
+import { formatTime, formatTimecode } from './utils'
+
+export interface PlayerState {
+ isPlaying: boolean
+ progress: number // 0 to 100
+ currentTime: number
+ duration: number
+ volume: number
+ isMuted: boolean
+ isLooping: boolean
+ playbackRate: number
+ isFullScreen: boolean
+ showFrames: boolean // Toggle between time (02:30) and frames (1234)
+ currentResolution: string // 'Original' or '720p', '480p' etc.
+ currentSrc?: string
+}
+
+export type DisplayTranscode = VideoTranscode & { resolution: string }
+
+export interface ControlBarProps {
+ state: PlayerState
+ zoom: number
+ isControlsVisible: boolean
+ buffered: number
+ data: AssetInfo
+ resolutions: DisplayTranscode[]
+ togglePlay: () => void
+ toggleLoop: () => void
+ toggleMute: () => void
+ handleVolumeChange: (newVolume: number) => void
+ changePlaybackRate: (rate: number) => void
+ changeResolution: (res: DisplayTranscode) => void
+ handleDownload: (key: string) => void
+ toggleFullScreen: () => void
+ onZoomChange: (zoom: number) => void
+ onZoomReset: () => void
+ // Frame-accurate props
+ frameRate: number
+ totalFrames: number
+ currentFrame: number
+ seekToFrame: (frame: number) => Promise | void
+}
+
+export const VideoControlBar: React.FC = ({
+ state,
+ zoom,
+ isControlsVisible,
+ buffered,
+ data,
+ resolutions,
+ togglePlay,
+ toggleLoop,
+ toggleMute,
+ handleVolumeChange,
+ changePlaybackRate,
+ changeResolution,
+ handleDownload,
+ toggleFullScreen,
+ onZoomChange,
+ onZoomReset,
+ frameRate,
+ totalFrames,
+ currentFrame,
+ seekToFrame,
+}) => {
+ const { videoTimeDisplayMode, setVideoTimeDisplayMode } = useUiStore()
+
+ if (!data.media?.metadata) {
+ return null
+ }
+
+ const previewResolutions = resolutions.filter((r) => !r.isRaw)
+
+ const startTimecode = data.media?.metadata?.startTimecode
+ const displayTotalFrames = Math.max(0, totalFrames - 1)
+ const displayString =
+ videoTimeDisplayMode === 'frames'
+ ? `${currentFrame} / ${displayTotalFrames} fr`
+ : videoTimeDisplayMode === 'standard'
+ ? `${formatTimecode(currentFrame, frameRate, 'standard')} / ${formatTime(totalFrames / frameRate)}`
+ : `${formatTimecode(currentFrame, frameRate, videoTimeDisplayMode, startTimecode)} / ${formatTimecode(displayTotalFrames, frameRate, videoTimeDisplayMode, startTimecode)}`
+
+ return (
+
+ {/* Progress Bar */}
+
+
+ {/* Lower Controls Row */}
+
+ {/* Left Side: Play, Vol, Time */}
+
+
+
+
+
+
+
+
+
+
+ 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' && (
+
+ )}
+
+
+
+
+
+
+ {/* Right Side: Zoom, Speed, Res, Download, Fullscreen */}
+
+ {/* Zoom Controls */}
+
+
+
+
+ {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
+
+ ))}
+
+
+
+ {/* Resolution Selector */}
+
+
+
+
+
+
+ Quality
+ {previewResolutions.map((res) => (
+ changeResolution(res)}
+ className={cn(
+ 'flex w-full items-center justify-between',
+ state.currentResolution === res.resolution
+ ? 'text-primary font-medium'
+ : 'text-foreground',
+ )}
+ >
+ {res.resolution}
+
+ {res.width}x{res.height}
+
+
+ ))}
+
+
+
+ {/* Download */}
+
+
+
+
+
+ Download
+ {resolutions.map((res) => (
+ handleDownload(res.key ?? '')}
+ className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
+ >
+ {res.resolution}
+
+ {res.isRaw ? data.name?.split('.').pop()?.toUpperCase() || 'RAW' : 'MP4'}
+
+
+ ))}
+
+
+
+ {/* Fullscreen */}
+
+
+
+
+ )
+}
diff --git a/packages/webui/components/viewers/video-player.tsx b/packages/webui/components/viewers/video-player.tsx
index 2a01cfab..02ffec3f 100644
--- a/packages/webui/components/viewers/video-player.tsx
+++ b/packages/webui/components/viewers/video-player.tsx
@@ -1,56 +1,17 @@
-import type { AssetInfo, VideoTranscode } from '@shumai/dtos'
+import type { AssetInfo } from '@shumai/dtos'
import { client } from '@/ui/api/client'
import { cn } from '@/ui/lib/utils'
-import {
- Check,
- ChevronDown,
- Download,
- Maximize,
- Minimize,
- Minus,
- Pause,
- Play,
- Plus,
- Repeat,
- Settings,
- Volume2,
- VolumeX,
-} from 'lucide-react'
+import { Play } from 'lucide-react'
import React, { useCallback, useEffect, useRef, useState } from 'react'
import videojs from 'video.js'
import type Player from 'video.js/dist/types/player'
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuLabel,
- DropdownMenuTrigger,
-} from '../ui/dropdown-menu'
-import { Slider } from '../ui/slider'
-import ProgressBar from './progress-bar'
-import { formatTimecode, formatTime } from './utils'
import { useFramePlayer } from './use-frame-player'
-import { useUiStore } from '@/ui/stores/ui'
+import { VideoControlBar, type PlayerState, type DisplayTranscode } from './video-control-bar'
import type { Annotation } from '@/ui/types'
import DrawingCanvas from '../drawing-canvas'
import { useAnnotationStore } from '@/ui/stores/annotation-store'
-export interface PlayerState {
- isPlaying: boolean
- progress: number // 0 to 100
- currentTime: number
- duration: number
- volume: number
- isMuted: boolean
- isLooping: boolean
- playbackRate: number
- isFullScreen: boolean
- showFrames: boolean // Toggle between time (02:30) and frames (1234)
- currentResolution: string // 'Original' or '720p', '480p' etc.
- currentSrc?: string
-}
-
interface VideoPlayerProps {
data: AssetInfo
playerRef?: React.RefObject
@@ -63,323 +24,6 @@ interface VideoPlayerProps {
children?: React.ReactNode
}
-type DisplayTranscode = VideoTranscode & { resolution: string }
-
-interface ControlBarProps {
- state: PlayerState
- zoom: number
- isControlsVisible: boolean
- buffered: number
- data: AssetInfo
- resolutions: DisplayTranscode[]
- togglePlay: () => void
- toggleLoop: () => void
- toggleMute: () => void
- handleVolumeChange: (newVolume: number) => void
- changePlaybackRate: (rate: number) => void
- changeResolution: (res: DisplayTranscode) => void
- handleDownload: (key: string) => void
- toggleFullScreen: () => void
- onZoomChange: (zoom: number) => void
- onZoomReset: () => void
- // Frame-accurate props
- frameRate: number
- totalFrames: number
- currentFrame: number
- seekToFrame: (frame: number) => Promise
-}
-
-const ControlBar: React.FC = ({
- state,
- zoom,
- isControlsVisible,
- buffered,
- data,
- resolutions,
- togglePlay,
- toggleLoop,
- toggleMute,
- handleVolumeChange,
- changePlaybackRate,
- changeResolution,
- handleDownload,
- toggleFullScreen,
- onZoomChange,
- onZoomReset,
- frameRate,
- totalFrames,
- currentFrame,
- seekToFrame,
-}) => {
- if (!data.media?.metadata) {
- return null
- }
-
- const previewResolutions = resolutions.filter((r) => !r.isRaw)
-
- const { videoTimeDisplayMode, setVideoTimeDisplayMode } = useUiStore()
-
- const startTimecode = data.media?.metadata?.startTimecode
- const displayTotalFrames = Math.max(0, totalFrames - 1)
- const displayString =
- videoTimeDisplayMode === 'frames'
- ? `${currentFrame} / ${displayTotalFrames} fr`
- : videoTimeDisplayMode === 'standard'
- ? `${formatTimecode(currentFrame, frameRate, 'standard')} / ${formatTime(totalFrames / frameRate)}`
- : `${formatTimecode(currentFrame, frameRate, videoTimeDisplayMode, startTimecode)} / ${formatTimecode(displayTotalFrames, frameRate, videoTimeDisplayMode, startTimecode)}`
-
- return (
-
- {/* Progress Bar */}
-
-
- {/* Lower Controls Row */}
-
- {/* Left Side: Play, Vol, Time */}
-
-
-
-
-
-
-
-
-
-
- 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' && (
-
- )}
-
-
-
-
-
-
- {/* Right Side: Zoom, Speed, Res, Download, Fullscreen */}
-
- {/* Zoom Controls */}
-
-
-
-
- {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
-
- ))}
-
-
-
- {/* Resolution Selector */}
-
-
-
-
-
-
- Quality
- {previewResolutions.map((res) => (
- changeResolution(res)}
- className={cn(
- 'flex w-full items-center justify-between',
- state.currentResolution === res.resolution
- ? 'text-primary font-medium'
- : 'text-foreground',
- )}
- >
- {res.resolution}
-
- {res.width}x{res.height}
-
-
- ))}
-
-
-
- {/* Download */}
-
-
-
-
-
- Download
- {resolutions.map((res) => (
- handleDownload(res.key ?? '')}
- className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
- >
- {res.resolution}
-
- {res.isRaw ? data.name?.split('.').pop()?.toUpperCase() || 'RAW' : 'MP4'}
-
-
- ))}
-
-
-
- {/* Fullscreen */}
-
-
-
-
- )
-}
-
const VideoPlayer: React.FC = ({
data,
playerRef: passedPlayerRef,
@@ -958,7 +602,7 @@ const VideoPlayer: React.FC = ({
-