fix(video): preserve transcript seek timestamps

This commit is contained in:
yiling
2026-12-03 15:25:28 +08:00
parent 3952928b88
commit 5daa2a8f92
9 changed files with 262 additions and 44 deletions
@@ -88,7 +88,7 @@ const SegmentRow = memo(function SegmentRow({
) {
return
}
mediaControllerRef.current?.seekTo(segment.startMs / 1000)
mediaControllerRef.current?.seekTo(segment.startMs / 1000, { exact: true })
}}
>
<span className="mb-1 block font-mono text-xs tabular-nums text-muted-foreground" dir="ltr">
@@ -29,4 +29,14 @@ describe('createTranscriptTimeline', () => {
expect(at(4000)).toBeUndefined()
expect(createTranscriptTimeline([])(0)).toBeUndefined()
})
it('uses the new segment at an exact millisecond after converting the seek through seconds', () => {
const at = createTranscriptTimeline([
{ id: 'before', startMs: 1800, endMs: 2010, text: '' },
{ id: 'after', startMs: 2010, endMs: 2200, text: '' },
])
expect(at(2009.999)).toBe('before')
expect(at((2010 / 1000) * 1000)).toBe('after')
})
})
@@ -8,7 +8,9 @@ export function createTranscriptTimeline(segments: TranscriptSegment[]) {
return { segment, latestEndMs }
})
return (timeMs: number): string | undefined => {
return (playbackTimeMs: number): string | undefined => {
// Remove floating-point noise around millisecond boundaries while keeping microsecond precision.
const timeMs = Math.round(playbackTimeMs * 1000) / 1000
let first = 0
let last = timeline.length
while (first < last) {