feat(webui): support jumping to video timestamp from search results

This commit is contained in:
yiling
2026-06-18 20:35:50 +08:00
parent 4c7ff6f58f
commit 3b7fc410b2
7 changed files with 51 additions and 3 deletions
@@ -18,6 +18,7 @@ type FileViewerProps = {
onPause?: () => void
onTimeUpdate?: (time: number) => void
annotations?: Annotation[]
startTime?: number
children?: ReactNode
}
@@ -28,6 +29,7 @@ export function FileViewer({
onPause,
onTimeUpdate,
annotations,
startTime,
children,
}: FileViewerProps) {
const { width: screenWidth } = useScreenSize()
@@ -308,6 +310,7 @@ export function FileViewer({
onPause={onPause}
onTimeUpdate={onTimeUpdate}
annotations={displayAnnotations}
startTime={startTime}
>
{children}
</VideoPlayer>
@@ -33,12 +33,14 @@ interface PublicShareManagerProps {
}
initialFolderId?: string
initialFileId?: string
startTime?: number
}
export function PublicShareManager({
shareInfo,
initialFolderId,
initialFileId,
startTime,
}: PublicShareManagerProps) {
const navigate = useNavigate()
const [password, setPassword] = useState(() => {
@@ -387,6 +389,7 @@ export function PublicShareManager({
onPlay={handlePlay}
onTimeUpdate={setCurrentTime}
annotations={annotations}
startTime={startTime}
/>
)}
</div>
@@ -242,7 +242,10 @@ export function SearchFilterDialog({
navigate({
to: '/projects/$projectId/files/$fileId',
params: { projectId, fileId: item.versionStack ? item.versionStack.id : item.id! },
search: { version: undefined },
search: {
version: undefined,
start: item.startTime && item.startTime > 0 ? item.startTime : undefined,
},
})
}
onOpenChange(false)
@@ -53,6 +53,7 @@ interface VideoPlayerProps {
onPause?: () => void
onTimeUpdate?: (time: number) => void
annotations?: Annotation[]
startTime?: number
children?: React.ReactNode
}
@@ -311,6 +312,7 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
onPause,
onTimeUpdate,
annotations,
startTime,
children,
}) => {
const localPlayerRef = useRef<Player | null>(null)
@@ -550,6 +552,13 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
// Set initial state
player.volume(state.volume)
// Seek to startTime if provided
if (startTime && startTime > 0) {
player.ready(() => {
player.currentTime(startTime)
})
}
// 4. Cleanup
return () => {
if (player && !player.isDisposed()) {
@@ -559,6 +568,18 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
}
}, [data])
// Handle changes to startTime (e.g., clicking different chunks in search results)
useEffect(() => {
const player = playerRef.current
if (player && startTime !== undefined && startTime !== null && startTime > 0) {
// Only seek if the difference is significant (e.g., > 1s) to avoid jumping due to small precision differences
const current = player.currentTime() || 0
if (Math.abs(current - startTime) > 1) {
player.currentTime(startTime)
}
}
}, [startTime, playerRef])
// Smooth progress updates using requestAnimationFrame when playing
useEffect(() => {
let animationFrameId: number
@@ -21,7 +21,8 @@ import type Player from 'video.js/dist/types/player'
function FileViewPage() {
const { projectId, fileId } = Route.useParams()
const search = Route.useSearch()
const versionAssetId = (search as { version?: string }).version
const versionAssetId = search.version
const startTime = search.start
const activeFileId = versionAssetId || fileId
const videoRef = useRef<Player | null>(null)
@@ -328,6 +329,7 @@ function FileViewPage() {
onPlay={handlePlay}
onTimeUpdate={setCurrentTime}
annotations={annotations}
startTime={startTime}
>
{carouselState.show && (
<FileViewerLeftSidebar
@@ -373,6 +375,7 @@ export const Route = createFileRoute('/projects/$projectId/files/$fileId')({
validateSearch: (search: Record<string, unknown>) => {
return {
version: (search.version as string) || undefined,
}
start: search.start ? Number(search.start) : undefined,
} as { version?: string; start?: number }
},
})
@@ -5,6 +5,7 @@ import { createFileRoute } from '@tanstack/react-router'
function PublicShareFilePage() {
const { shareId, fileId } = Route.useParams()
const { start } = Route.useSearch()
const { data: shareInfo } = useQuery({
queryKey: ['share-info', shareId],
@@ -27,10 +28,16 @@ function PublicShareFilePage() {
isDisabled: shareInfo.isDisabled ?? false,
}}
initialFileId={fileId}
startTime={start}
/>
)
}
export const Route = createFileRoute('/share/$shareId/files/$fileId')({
component: PublicShareFilePage,
validateSearch: (search: Record<string, unknown>) => {
return {
start: search.start ? Number(search.start) : undefined,
} as { start?: number }
},
})