diff --git a/.changeset/fixed_voice_message_scrubbingseeking_on_firefox_by_switching_the_recorder_from_webm_no_seek_index_to_oggopus.md b/.changeset/fixed_voice_message_scrubbingseeking_on_firefox_by_switching_the_recorder_from_webm_no_seek_index_to_oggopus.md new file mode 100644 index 00000000..7b7dd9a3 --- /dev/null +++ b/.changeset/fixed_voice_message_scrubbingseeking_on_firefox_by_switching_the_recorder_from_webm_no_seek_index_to_oggopus.md @@ -0,0 +1,5 @@ +--- +default: patch +--- + +# Fixed voice message scrubbing/seeking on Firefox by switching the recorder from WebM (no seek index) to Ogg/Opus. diff --git a/src/app/components/upload-card/UploadCardRenderer.tsx b/src/app/components/upload-card/UploadCardRenderer.tsx index 931215b6..d9fa444f 100644 --- a/src/app/components/upload-card/UploadCardRenderer.tsx +++ b/src/app/components/upload-card/UploadCardRenderer.tsx @@ -128,6 +128,10 @@ function PreviewAudio({ fileItem }: PreviewAudioProps) { return undefined; } const audio = new Audio(audioUrl); + audio.preload = 'auto'; + // Explicitly load so Firefox parses metadata immediately, making + // currentTime writable before the user has ever pressed play. + audio.load(); audioRef.current = audio; audio.onended = () => { @@ -177,13 +181,34 @@ function PreviewAudio({ fileItem }: PreviewAudioProps) { } }; + const seekTo = (audio: HTMLAudioElement, targetTime: number) => { + // Alias to a local const to satisfy no-param-reassign. + const el = audio; + if (el.seekable.length > 0) { + el.currentTime = targetTime; + setCurrentTime(targetTime); + } else { + // Metadata not yet loaded (Firefox, first scrub before load() resolves). + // Do NOT call load() again here — that resets currentTime to 0 and + // restarts the fetch. load() was already called in the useEffect; + // just wait for the in-flight loadedmetadata event. + el.addEventListener( + 'loadedmetadata', + () => { + el.currentTime = targetTime; + setCurrentTime(targetTime); + }, + { once: true } + ); + } + }; + const handleScrubClick = (e: React.MouseEvent) => { const audio = audioRef.current; if (!audio || !duration) return; const rect = e.currentTarget.getBoundingClientRect(); const ratio = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width)); - audio.currentTime = ratio * duration; - setCurrentTime(audio.currentTime); + seekTo(audio, ratio * duration); }; const handleKeyDown = (e: React.KeyboardEvent) => { @@ -209,8 +234,7 @@ function PreviewAudio({ fileItem }: PreviewAudioProps) { return; } - audio.currentTime = newTime; - setCurrentTime(newTime); + seekTo(audio, newTime); }; return ( diff --git a/src/app/plugins/voice-recorder-kit/supportedCodec.ts b/src/app/plugins/voice-recorder-kit/supportedCodec.ts index 445147cd..a1b09461 100644 --- a/src/app/plugins/voice-recorder-kit/supportedCodec.ts +++ b/src/app/plugins/voice-recorder-kit/supportedCodec.ts @@ -13,14 +13,17 @@ const safariPreferredCodecs = [ ]; const defaultPreferredCodecs = [ - // Chromium / Firefox stable path. + // Firefox: ogg produces seekable blobs; webm passes isTypeSupported() but + // records without a cue index so currentTime assignment silently fails. + // Must come before webm so Firefox picks ogg. + 'audio/ogg;codecs=opus', + 'audio/ogg', + // Chromium: webm is seekable and preferred. Since Chromium doesn't support + // ogg recording, it will skip the above and land here. 'audio/webm;codecs=opus', 'audio/webm', - // Firefox - 'audio/ogg;codecs=opus', - 'audio/ogg;codecs=vorbis', - 'audio/ogg', // Fallbacks + 'audio/ogg;codecs=vorbis', 'audio/wav;codecs=1', 'audio/wav', 'audio/mpeg',