Add pause/resume media playback during recording#126
Open
directedbit wants to merge 3 commits intoStarmel:masterfrom
Open
Add pause/resume media playback during recording#126directedbit wants to merge 3 commits intoStarmel:masterfrom
directedbit wants to merge 3 commits intoStarmel:masterfrom
Conversation
When recording starts, automatically pauses any currently playing media (Feisch, Spotify, Apple Music, etc.) via system media key simulation. Resumes playback when recording stops or is cancelled. Uses the private MediaRemote framework to detect playback state so we only pause when media is actually playing. Feature is enabled by default with a toggle in Settings. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The initial implementation used CGEvent to simulate media key presses, which silently failed without Accessibility permissions. Switched to using MRMediaRemoteSendCommand from the private MediaRemote framework, which sends explicit kMRPause/kMRPlay commands rather than toggling. Also removed the isMediaCurrentlyPlaying() guard that used MRMediaRemoteGetNowPlayingApplicationIsPlaying with a synchronous DispatchSemaphore. When called from the main thread (as the app does), this deadlocked — the MediaRemote callback could not complete while the main thread was blocked, causing the semaphore to time out and the pause to never be sent. Since kMRPause is a no-op when nothing is playing, the guard was unnecessary. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The previous version always sent kMRPause (which is harmless), but then set didPauseMedia=true unconditionally. On recording stop, resumeMedia() would send kMRPlay even when nothing had been playing, causing media to start unexpectedly. Now checks MRMediaRemoteGetNowPlayingApplicationIsPlaying before pausing. The check is dispatched to a background thread to avoid the main-thread deadlock that caused the original implementation to fail (the MediaRemote callback needs the main run loop to complete, which can't happen if the main thread is blocked by a semaphore). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NX_KEYTYPE_PLAY) so it works universally with all media playersMediaRemoteframework) to avoid accidentally starting playbackImplementation Details
MediaPlaybackController.swift— New singleton that handles detecting playback state and sending system media key eventsAudioRecorder.swift— Integrates pause onstartRecording()and resume onstopRecording()/cancelRecording()AppPreferences.swift— NewpauseMediaOnRecordpreference (default:true)Settings.swift— ViewModel property + UI toggle with description textTest plan
🤖 Generated with Claude Code