Skip to content

fix(chat): wait for the music of another app to stop before a voice recording starts - #6930

Open
ToteMeiSter wants to merge 1 commit into
masterfrom
fix/recording-music-silence
Open

ToteMeiSter wants to merge 1 commit into
masterfrom
fix/recording-music-silence

Conversation

@ToteMeiSter

Copy link
Copy Markdown
Contributor

Fixes the end of another app's music being recorded in the first moments of a voice message.

Recording a voice message asks for the audio focus and opens the microphone in the same call. The music player of another app pauses some time after it lost the focus, so the first second of the message contains the end of the music from the speaker.

AudioFocusRequestManager.audioFocusRequest gets waitForOtherAudio. After the focus is granted the callback waits until AudioManager.isMusicActive is false (MusicSilenceGate: polls every 50 ms, at most 1 s). Without music there is no delay. Voice recording (ChatViewModel.startAudioRecording) and the mic visualizer (MessageInputViewModel.startMicInput) use it. Giving the focus back drops a start that still waits, and stopAndSendAudioRecording does not send a recording that was released before it started.

Known limit: with music the recording starts up to 1 s later. The "too short" check counts from the press, so a very short hold while music plays may send nothing.

To test: play music in another app, hold the voice record button for about 3 s, say a phrase, release. The music pauses at the press, the message does not contain the music, and the music comes back after sending.

Unit tests: MusicSilenceBeforeCaptureTest (6 tests, fail without the change). Real capture cannot be tested in unit tests.

Tested on: Huawei DEL-LX9 (Android 12), on a develop build of the fork that includes this fix.

🖼️ 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

…ecording starts

The recording asked for the audio focus and opened the microphone in the same call. The player of another app pauses some time after it lost the focus, so the first moments of a voice message contained the end of the music from the speaker. After the focus is granted, the start of the recording now waits until AudioManager.isMusicActive is false, for at most one second; without music there is no delay. Giving the focus back drops a start that still waits, and a recording that was released before it started is not sent.

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 195a1b7
Version 6930
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.

@github-actions

Copy link
Copy Markdown
Contributor

Codacy

Lint

TypemasterPR
Warnings138138
Errors1515

SpotBugs

CategoryBaseNew
Bad practice77
Correctness88
Dodgy code4040
Internationalization33
Malicious code vulnerability33
Performance88
Security1111
Total8080

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