From b36ed26c3cecf01403101b20c2f8007283050973 Mon Sep 17 00:00:00 2001 From: Alanna Date: Mon, 5 Oct 2026 10:09:37 -0400 Subject: [PATCH] fix(ui): don't resume paused music on Media Session pause action The player library maps both the Media Session "play" and "pause" actions to togglePlay. When the OS sends "pause" to an already-paused player (e.g. macOS when a Zoom or phone call starts), playback resumes. Re-register both handlers so each only toggles in the matching state. Co-Authored-By: Claude Opus 5.5 --- ui/src/audioplayer/Player.jsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ui/src/audioplayer/Player.jsx b/ui/src/audioplayer/Player.jsx index c3d795b26..ef13c370b 100644 --- a/ui/src/audioplayer/Player.jsx +++ b/ui/src/audioplayer/Player.jsx @@ -424,6 +424,21 @@ const Player = () => { } }, [isMobilePlayer, audioInstance]) + // The player library maps both the Media Session "play" and "pause" actions + // to togglePlay, so an OS "pause" (e.g. when a call starts) resumes paused + // music. Re-register them so each only acts in the matching state. This runs + // after every player update, as the library re-registers its own handlers. + useEffect(() => { + if (!audioInstance || !('mediaSession' in navigator)) return + if (playerState.current?.isRadio) return + navigator.mediaSession.setActionHandler('play', () => { + if (audioInstance.paused) audioInstance.togglePlay() + }) + navigator.mediaSession.setActionHandler('pause', () => { + if (!audioInstance.paused) audioInstance.togglePlay() + }) + }, [audioInstance, playerState]) + // Report every seek (including programmatic ones the library does not surface // via onAudioSeeked, e.g. restartCurrentOnPrev). Debounce coalesces drag // bursts into one report at the final position.