fix: /record duration fallback so upper bound is never 0 in preview (#1256)
the previous fix covered duration=Infinity (Firefox behavior) but not
duration=0 (what Chrome reports for MediaRecorder webm blobs until
playback actually reaches EOF). so the user still saw "00:07 / 00:00"
during playback, with the upper bound only updating to the real value
at the end of the track.
two changes:
1. broaden the seek-to-EOF workaround to fire for any non-positive
or non-finite duration (0, NaN, Infinity), not just Infinity. new
isUsableDuration helper so the logic reads the same in both the
early-return and the durationchange listener.
2. add a capturedDuration fallback: in finalizeRecording we snapshot
the live-tick elapsedSeconds counter, and a new effectiveDuration
derived prefers the audio element's real duration once it becomes
usable, else falls back to the captured seconds. this means the
display shows a correct (1s-resolution) upper bound immediately on
entering preview, even during the brief window before the browser
has finished scanning the blob. the seek workaround still fires in
parallel so the audio element eventually reports its own
sub-second-accurate duration and we use that.
effectiveDuration also feeds playbackProgress and handleSeek, so the
waveform playhead sweeps correctly and clicks seek to the right
position even during the fallback window. capturedDuration is reset
to 0 in reRecord along with the other playback state.
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
authored by