feat(video): add timestamp support to comments

This commit is contained in:
yiling
2026-05-27 11:17:56 +08:00
parent ad8f3931f7
commit c048ceef28
12 changed files with 158 additions and 20 deletions
+10
View File
@@ -10,6 +10,16 @@ export const formatTime = (seconds: number): string => {
return `${mm}:${ss}`
}
export const formatTimestamp = (seconds: number, fps: number): string => {
if (isNaN(seconds)) return '00:00:00:00'
const hh = Math.floor(seconds / 3600)
const mm = Math.floor((seconds % 3600) / 60)
const ss = Math.floor(seconds % 60)
const ff = Math.floor((seconds % 1) * fps)
return `${hh.toString().padStart(2, '0')}:${mm.toString().padStart(2, '0')}:${ss.toString().padStart(2, '0')}:${ff.toString().padStart(2, '0')}`
}
export const formatFrame = (seconds: number, fps: number): number => {
if (isNaN(seconds) || !fps) return 0
return Math.floor(seconds * fps)
@@ -51,6 +51,7 @@ interface VideoPlayerProps {
playerRef?: React.RefObject<Player | null>
onPlay?: () => void
onPause?: () => void
onTimeUpdate?: (time: number) => void
annotations?: Annotation[]
}
@@ -299,6 +300,7 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
playerRef: passedPlayerRef,
onPlay,
onPause,
onTimeUpdate,
annotations,
}) => {
const localPlayerRef = useRef<Player | null>(null)
@@ -494,6 +496,10 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
duration: duration || prev.duration,
progress: duration > 0 ? (current / duration) * 100 : 0,
}))
if (onTimeUpdate) {
onTimeUpdate(current)
}
})
player.on('volumechange', () => {