Skip to content

fix(chat): pause the music of another app while a voice or video message plays - #6931

Open
ToteMeiSter wants to merge 2 commits into
masterfrom
fix/playback-audio-focus
Open

ToteMeiSter wants to merge 2 commits into
masterfrom
fix/playback-audio-focus

Conversation

@ToteMeiSter

@ToteMeiSter ToteMeiSter commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

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 default handleAudioFocus = 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: after ACTION_AUDIO_BECOMING_NOISY (headphones unplugged) AudioFocusRequestManager skipped 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: PlaybackAudioFocus holds 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 in VoiceMessageMediaService and in the video player of LargePreview. Both players now also pause when the headphones are unplugged. The focus is GAIN_TRANSIENT on purpose: ExoPlayer's own handleAudioFocus takes 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). The MediaController to 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

  • Nothing left

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not needed
  • 🔖 Capability is checked or not needed
  • 🔙 Backport requests are created or not needed: /backport to stable-xx.x
  • 📅 Milestone is set
  • 🌸 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

🤖 Generated with Claude Code

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>
@github-actions

Copy link
Copy Markdown
Contributor

📱 QA build

Download app-qa-debug.apk
QR code Open the QR code for this download
Commit 641c4d2
Version 6931
Available until 7 days after this build

The QA build installs alongside a released Nextcloud app, so you can keep
using your existing install while testing.

Downloading the file requires a GitHub account, so open this link on the
device you want to test on, or transfer the APK to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant