androidx / androidx/media

Listening to changes of current audio output

Open
#2,080 4 comments 0 reactions 1 assignee View on GitHub

@microkatz is already working on this.

Since Jan 28, 2025.

enhancement
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:
Image

Alternatives considered
  • Manually detecting routing changes with current Android APIs (e.g., AudioManager, AudioDeviceCallback, MediaRouter or silent AudioTrack with AudioRouting) has proven unreliable or inconsistent when the user switches audio outputs manually without disconnecting headphones.
  • AudioBecomingNoisy doesn't trigger when the user switches audio outputs manually and works only in one direction (from headphones to speaker).
  • Using C.USAGE_VOICE_COMMUNICATION can 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.