Request media audio focus when playing a voice message - #7454
Open
hayaksi1 wants to merge 1 commit into
Open
Conversation
Voice message playback asked for audio focus with USAGE_VOICE_COMMUNICATION, the same bucket as Element Call and voice message recording, while the player itself renders on the media stream. Audio policy layers act on the declared usage, so a car head unit switches to its call audio context and routes the playback away while the player keeps running. Declare USAGE_MEDIA (and STREAM_MUSIC on the legacy path) for playback, which is what the player actually renders. Recording and Element Call keep asking for voice communication focus.
Contributor
|
Thank you for your contribution! Here are a few things to check in the PR to ensure it's reviewed as quickly as possible:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Content
DefaultAudioFocusgroups voice message playback with Element Call and voice message recording, so it asks for audio focus withUSAGE_VOICE_COMMUNICATION(andSTREAM_VOICE_CALLon the pre-O path). The player that actually renders the audio uses the default media attributes, so what the app declares to the audio policy layer and what it renders disagree.Audio routing decisions are made from the declared usage. A car head unit that sees a voice-communication focus request switches to its call audio context, which routes the media output away while the player keeps running — the reporter's symptom of playback disappearing mid-message in Android Auto.
Declare
USAGE_MEDIA/STREAM_MUSICfor voice message playback, matching what the player renders and what the media viewer already declares. Recording keepsUSAGE_VOICE_COMMUNICATION, which is correct: it drives the capture path and the exclusive transient focus request next to it. Element Call is unchanged.The ducking policy is deliberately left alone, so playback still pauses rather than ducking.
Motivation and context
Part of #6276.
Tests
New
libraries/audio/impl/.../DefaultAudioFocusTest.ktasserts the usage each requester ends up declaring, via the shadow audio manager: media for voice message playback and the media viewer, voice communication for recording and Element Call. This required adding the common test dependencies to the module, which had no test source set. Run with./gradlew :libraries:audio:impl:testDebugUnitTest.The routing behaviour itself needs a car head unit and could not be reproduced here; the change is argued from the declared-versus-rendered mismatch in the code.
Tested devices
Checklist