Listening to changes of current audio output
@microkatz is already working on this.
Since Jan 28, 2025.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
Use case description
I’m developing an app that plays audio for users in a museum (like a virtual tour guide). The app needs to detect the current audio output device so it can automatically adjust the maximum volume. Specifically:
- Speaker mode: If the user is listening through the phone’s built-in speaker, the app lowers the volume (similar to a voice call), so it doesn’t disturb other visitors.
- Headphones (wired or wireless): The volume can be restored to normal or maximum.
Proposed solution
Add an API that allows apps to listen to changes of current audio output (e.g., speaker ↔ headphones ↔ Bluetooth).
This would enable apps to accurately respond in real time and adjust their audio behavior accordingly.
Users can change it here:
Alternatives considered
- Manually detecting routing changes with current Android APIs (e.g.,
AudioManager,AudioDeviceCallback,MediaRouteror silentAudioTrackwithAudioRouting) has proven unreliable or inconsistent when the user switches audio outputs manually without disconnecting headphones. AudioBecomingNoisydoesn't trigger when the user switches audio outputs manually and works only in one direction (from headphones to speaker).- Using
C.USAGE_VOICE_COMMUNICATIONcan mimic call-like audio, but it causes problems:- Google Assistant can’t stop playback while listening for voice.
- Incoming/outgoing phone calls may not automatically pause the playback.
- Other media apps might fail to stop or duck this playback.
Given these limitations, an official, reliable listener/callback for audio output routing changes in Media3/ExoPlayer would greatly simplify the development of apps with dynamic audio output requirements.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.