Skip to content

feat(audio): coordinate Android audio focus and auto-yield on interruptions - #41

Open
yanwuu wants to merge 1 commit into
shilapi:masterfrom
yanwuu:feat/audio-focus-coordination
Open

yanwuu wants to merge 1 commit into
shilapi:masterfrom
yanwuu:feat/audio-focus-coordination

Conversation

@yanwuu

@yanwuu yanwuu commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Introduce structured Android AudioFocus coordination for CarPlay media playback, automatically yielding audio to external car events (radio, Bluetooth calls, navigation announcements) and restoring playback seamlessly.


Problem

The media sink previously played decoded PCM audio straight to AudioTrack without requesting or monitoring Android AudioManager.OnAudioFocusChangeListener. When other audio sources in the car (such as native navigation alerts, cluster prompts, or external media apps) played, audio would either overlap harshly or compete for the hardware sound card.


Solution

  • Added AudioFocusCoordinator supporting modern AudioFocusRequest (API 26+) and legacy focus management with ducking and transient loss handling.
  • Wired into AndroidMediaSink to request focus before playback and automatically pause/duck when focus is lost.
  • Added user toggle in Settings to allow enabling/disabling AudioFocus management.

…ptions

Introduce system AudioFocus linkage to resolve issue shilapi#36 where native head-unit audio (e.g., Bluetooth phone calls, radio, navigation guidance) conflicts with CarPlay media playback.

1. AudioFocusCoordinator: requests system audio focus based on channel priority (MEDIA: GAIN, PHONE: GAIN_TRANSIENT, ASSISTANT: GAIN_TRANSIENT_MAY_DUCK).
2. Ducking & Auto-yield: ducks media playback to 20% volume on AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK, mutes media on AUDIOFOCUS_LOSS_TRANSIENT (e.g., car Bluetooth calls or native voice prompts), and restores full volume on AUDIOFOCUS_GAIN.
3. AirPlayPersistence & CarPlayHostActivity: adds user toggles for Audio Focus and temporary mute auto-yield with persistent storage and resolution summary.
4. AudioFocusCoordinatorTest: adds unit tests covering channel priority ordering and volume constants.
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