From 52909ef6240eb297fd42d610bb1f0132c7defce8 Mon Sep 17 00:00:00 2001 From: mattsigal Date: Mon, 8 Jun 2026 07:59:01 -0700 Subject: [PATCH] feat(playback): add headphone auto-pause on disconnection and fix iOS/tvOS play/pause media controls - Listen to AudioSession.becomingNoisyEventStream and pause playback when headphones are disconnected/unplugged. - Add MediaAction.play and MediaAction.pause to systemActions in MoonfinAudioHandler to enable iOS Lock Screen and AirPods Pro media key controls. - Initialize MoonfinAudioHandler on iOS and tvOS (Apple TV) to ensure Now Playing details and controls work properly across all Apple devices. --- lib/main.dart | 5 ++++- lib/playback/audio_handler.dart | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/main.dart b/lib/main.dart index 4fd1a34a..79ec927b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -309,7 +309,7 @@ void main() async { await notificationService.initialize(); } catch (_) {} - if (PlatformDetection.isMobile) { + if (PlatformDetection.isMobile || PlatformDetection.isIOS) { try { await initAudioService( manager: GetIt.instance(), @@ -333,6 +333,9 @@ void main() async { ), )); await session.setActive(true); + session.becomingNoisyEventStream.listen((_) { + GetIt.instance().pause(); + }); } catch (_) {} if (!GetIt.instance.isRegistered()) { diff --git a/lib/playback/audio_handler.dart b/lib/playback/audio_handler.dart index b3b954e5..7774be0d 100644 --- a/lib/playback/audio_handler.dart +++ b/lib/playback/audio_handler.dart @@ -50,6 +50,8 @@ class MoonfinAudioHandler extends BaseAudioHandler controls: controls, systemActions: const { MediaAction.seek, + MediaAction.play, + MediaAction.pause, MediaAction.skipToNext, MediaAction.skipToPrevious, },