fix(editor): refresh companion audio preview#586
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughVideoEditor adds a refresh key state and calls audio.playSourceAudioPreview() when resuming playback. useAudioPreviewSync exposes a stable playSourceAudioPreview callback. The refresh key is passed through useVideoEditorAudio to useSourceAudioFallback to re-fetch fallback audio when sessions change. ChangesAudio Playback and Fallback Refresh
Sequence Diagram(s)sequenceDiagram
participant VideoEditor
participant useVideoEditorAudio
participant useAudioPreviewSync
VideoEditor->>useVideoEditorAudio: call hook with sourceAudioFallbackRefreshKey
useVideoEditorAudio->>useAudioPreviewSync: call hook
useAudioPreviewSync->>useAudioPreviewSync: setup callbacks as useCallback
useAudioPreviewSync-->>useVideoEditorAudio: return playSourceAudioPreview
useVideoEditorAudio-->>VideoEditor: return playSourceAudioPreview and audio state
VideoEditor->>VideoEditor: user toggles play
VideoEditor->>useVideoEditorAudio: call audio.playSourceAudioPreview()
useVideoEditorAudio->>useAudioPreviewSync: invoke playSourceAudioPreview
useAudioPreviewSync->>useAudioPreviewSync: ensure audio context and play sources
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/components/video-editor/VideoEditor.tsx (2)
2301-2323:⚠️ Potential issue | 🟠 Major | ⚡ Quick winNormalize
session.videoPathbefore matching the active source.Line 2234 already runs this field through
fromFileUrl(...), but this handler compares the raw event payload tovideoSourcePath. IfonRecordingSessionChangeddelivers the same file-URL shape, the equality check never matches andsetSourceAudioFallbackRefreshKey()never fires, so the late sidecar refresh path is skipped entirely.Suggested fix
return window.electronAPI.onRecordingSessionChanged((session) => { + const sessionSourcePath = session?.videoPath ? fromFileUrl(session.videoPath) : null; console.log("[VideoEditor] onRecordingSessionChanged received!", { hasSession: Boolean(session), hasSessionVideoPath: Boolean(session?.videoPath), hasVideoSourcePath: Boolean(videoSourcePath), - match: session?.videoPath === videoSourcePath, + match: sessionSourcePath === videoSourcePath, hasWebcamPath: Boolean(session?.webcamPath), }); - if (!session || session.videoPath !== videoSourcePath) { + if (!session || sessionSourcePath !== videoSourcePath) { return; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/components/video-editor/VideoEditor.tsx` around lines 2301 - 2323, The handler passed to window.electronAPI.onRecordingSessionChanged compares the raw session.videoPath to videoSourcePath, which can mismatch if one side was normalized earlier with fromFileUrl; update the callback in onRecordingSessionChanged to normalize session.videoPath via the same fromFileUrl(...) utility (use the same import/utility already used elsewhere) before logging and before the equality check, then use that normalized value for the if-check and for setting webcam/source fields so setSourceAudioFallbackRefreshKey(...) runs when paths truly match.
3188-3198:⚠️ Potential issue | 🟠 Major | ⚡ Quick winRoute all resume paths through the same source-audio helper.
This fixes the toolbar Play button, but Lines 3898-3911 still resume playback with
playback.play()directly. Starting preview via the spacebar shortcut can still miss late companion audio, so the new behavior remains inconsistent.Suggested fix
+const startPlayback = useCallback(() => { + const playback = videoPlaybackRef.current; + if (!playback?.video) return; + audio.playSourceAudioPreview(); + void playback.play().catch((err) => console.error("Video play failed:", err)); +}, [audio.playSourceAudioPreview]); + function togglePlayPause() { const playback = videoPlaybackRef.current; const video = playback?.video; if (!playback || !video) return; if (!video.paused && !video.ended) { playback.pause(); } else { - audio.playSourceAudioPreview(); - playback.play().catch((err) => console.error("Video play failed:", err)); + startPlayback(); } }Then use
startPlayback()in the shortcut branch too.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/components/video-editor/VideoEditor.tsx` around lines 3188 - 3198, The resume logic must go through the same helper used by the toolbar: replace direct uses of playback.play() in the keyboard shortcut/resume branch with a call to startPlayback() (the same helper that ensures audio.playSourceAudioPreview() runs before starting video and wraps playback.play() with proper error handling); locate the spacebar/shortcut handler (the branch currently calling playback.play() directly) and change it to invoke startPlayback(), and update any other resume paths that call playback.play() directly so all resume flows use startPlayback().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/components/video-editor/VideoEditor.tsx`:
- Around line 2301-2323: The handler passed to
window.electronAPI.onRecordingSessionChanged compares the raw session.videoPath
to videoSourcePath, which can mismatch if one side was normalized earlier with
fromFileUrl; update the callback in onRecordingSessionChanged to normalize
session.videoPath via the same fromFileUrl(...) utility (use the same
import/utility already used elsewhere) before logging and before the equality
check, then use that normalized value for the if-check and for setting
webcam/source fields so setSourceAudioFallbackRefreshKey(...) runs when paths
truly match.
- Around line 3188-3198: The resume logic must go through the same helper used
by the toolbar: replace direct uses of playback.play() in the keyboard
shortcut/resume branch with a call to startPlayback() (the same helper that
ensures audio.playSourceAudioPreview() runs before starting video and wraps
playback.play() with proper error handling); locate the spacebar/shortcut
handler (the branch currently calling playback.play() directly) and change it to
invoke startPlayback(), and update any other resume paths that call
playback.play() directly so all resume flows use startPlayback().
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 2b0aafde-5c76-4bc5-bbc5-3b488e640520
📒 Files selected for processing (4)
src/components/video-editor/VideoEditor.tsxsrc/components/video-editor/audio/useAudioPreviewSync.tssrc/components/video-editor/audio/useSourceAudioFallback.tssrc/components/video-editor/audio/useVideoEditorAudio.ts
Summary
.mic.wavsidecars are audible in preview.Root cause
Native Windows recordings can open the editor before the browser microphone sidecar finishes writing. Export reads companion audio later and succeeds, but editor preview can miss or fail to unlock the
.mic.wavsidecar after it becomes available.Validation
npx biome check src/components/video-editor/VideoEditor.tsx src/components/video-editor/audio/useSourceAudioFallback.ts src/components/video-editor/audio/useVideoEditorAudio.ts src/components/video-editor/audio/useAudioPreviewSync.ts --formatter-enabled=falsenpx tsc --noEmit --pretty falsenpm test -- src/lib/exporter/sourceTrackRoutingPolicy.test.ts src/lib/exporter/sourceAudioFallback.test.tsgit diff --checkSummary by CodeRabbit
Bug Fixes
Refactor