Skip to content

feat(android): pause playback when audio output becomes noisy - #77

Open
Louis292 wants to merge 1 commit into
fossisawesome:mainfrom
Louis292:feat/pause-on-audio-becoming-noisy
Open

feat(android): pause playback when audio output becomes noisy#77
Louis292 wants to merge 1 commit into
fossisawesome:mainfrom
Louis292:feat/pause-on-audio-becoming-noisy

Conversation

@Louis292

@Louis292 Louis292 commented Sep 2, 2026

Copy link
Copy Markdown

Summary

Pauses playback automatically when the audio output becomes noisy — i.e. when headphones are unplugged or a Bluetooth audio device disconnects.

This matches the behaviour described in the Android docs for ACTION_AUDIO_BECOMING_NOISY and is the standard way to avoid blasting audio through the speaker unexpectedly.

Changes

NoisyAudioReceiver.kt (new)

  • BroadcastReceiver that listens for AudioManager.ACTION_AUDIO_BECOMING_NOISY.
  • Calls PlaybackController.pause() on receipt.

NowPlayingService.kt

  • Registers NoisyAudioReceiver in onCreate() with RECEIVER_NOT_EXPORTED (the intent is always system-delivered, so the flag has no practical effect, but is required on API 33+).
  • Unregisters in onDestroy().
  • Registration is on the foreground service so it remains active while the app is backgrounded.

Testing

  • Play a track with wired headphones → unplug → playback pauses.
  • Play a track with Bluetooth → disconnect the device → playback pauses.
  • Pause, then unplug → stays paused (no state change).

…connect)

- Add NoisyAudioReceiver: BroadcastReceiver for ACTION_AUDIO_BECOMING_NOISY
  that calls PlaybackController.pause()
- NowPlayingService: register the receiver in onCreate(), unregister in
  onDestroy(); registered on the foreground service so it works when the
  app is backgrounded (RECEIVER_NOT_EXPORTED, system delivers regardless)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant