Repository navigation
fix(chat): pause the music of another app while a voice or video message plays - #6931
Open
ToteMeiSter wants to merge 2 commits into
Open
ToteMeiSter wants to merge 2 commits into
ToteMeiSter wants to merge 2 commits into
Conversation
After ACTION_AUDIO_BECOMING_NOISY the audio focus manager skipped every further request, also the one that gives the focus back. The focus and the broadcast receiver stayed registered, and the music of another app did not come back. Only a request for the focus is answered at once in that state now; abandoning the focus goes through. Assisted-by: Claude-Code:claude-sonnet-5-5 Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru>
…age plays The players of the voice messages (VoiceMessageMediaService) and of the video attachments (LargePreview) are ExoPlayers built with the default handleAudioFocus = false, so they never asked for the audio focus and the music of another app kept playing. PlaybackAudioFocus holds a transient audio focus while a player plays, gives it back when the player pauses or ends, and pauses the player when the focus is lost. The focus is transient on purpose: with a permanent one the music would not come back after the message. The players also pause when the headphones are unplugged. Assisted-by: Claude-Code:claude-sonnet-5-5 Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru>
Contributor
📱 QA build
The QA build installs alongside a released Nextcloud app, so you can keep Downloading the file requires a GitHub account, so open this link on the |
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.
Makes voice messages and video attachments pause the music of another app while they play, and gives the audio focus back when they stop.
The players of voice messages (
VoiceMessageMediaService) and of video attachments (LargePreview) are ExoPlayers with the defaulthandleAudioFocus = false. They never ask for the audio focus, so the music of another app keeps playing under the message. A second defect hides behind it: afterACTION_AUDIO_BECOMING_NOISY(headphones unplugged)AudioFocusRequestManagerskipped every request, also the one that gives the focus back. The focus and the broadcast receiver stayed registered, and the music did not come back.The PR has two commits. First,
fix(chat): give the audio focus back after the headphones were unplugged: after the noisy broadcast only a request for the focus is answered at once, abandoning the focus goes through. Second,fix(chat): pause the music of another app while a voice or video message plays:PlaybackAudioFocusholds a transient audio focus while a player plays, gives it back on pause or end, and pauses the player when the focus is lost. It is used inVoiceMessageMediaServiceand in the video player ofLargePreview. Both players now also pause when the headphones are unplugged. The focus isGAIN_TRANSIENTon purpose: ExoPlayer's ownhandleAudioFocustakes a permanent focus for media, so the music would not come back after the message.To test: play music in another app, then play a voice message in a chat (and a video attachment, if there is one). The music pauses while the message plays and comes back when it is paused or ends. Unplug the headphones during the message: it pauses and the music comes back.
Unit tests:
PlaybackAudioFocusTest,VoiceMessageMediaServiceFocusTest(plays a real file in the player of the real service; fails without the change),AudioFocusAfterBecomingNoisyTest(fails without the fix). TheMediaControllerto service path is not reachable in a unit test.Tested on: Huawei DEL-LX9 (Android 12), on a develop build of the fork that includes this fix.
Overlaps with #6840: both change
VoiceMessageMediaService.kt.🖼️ Screenshots
No UI change.
🚧 TODO
🏁 Checklist
/backport to stable-xx.x🤖 AI (if applicable)
🤖 Generated with Claude Code