[Android] Recording interruptions without audio focus (observeRecordingInterruptions / isRecordingSilenced)
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 15/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- android, cpp, kotlin, react-native, typescript
- Ambito
- audio-video-rtc, mobile
Direzione di ricerca
Start with the proposed RecordingSilenceListener.kt and the AudioManager.ts API surface the issue links, then find where MediaSessionManager.cleanup() and the recorder's pause() live. Do not start coding until a maintainer decides on the opt-in androidSharedInput recorder option, since the input stream's sharing mode depends on it. Done means the API is agreed, the Android 29+ listener is wired with a no-op elsewhere, and the old-arch spec, web no-op and Jest mock are updated.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Feature Request
Problem
On Android, the only way to learn that a recording was interrupted (a phone call, a VoIP call, the Assistant, another recorder) is AudioManager.observeAudioInterruptions(...), which requests audio focus. Focus is a playback contract, and for a recording-only app it has two costs:
- Starting a recording stops the user's music.
AUDIOFOCUS_GAINmakes Spotify/YouTube/a play-along app pause. Apps where people record themselves playing along to a backing track or a metronome app can't use it. - Other apps' playback pauses the recording, and it never comes back. When the user starts music, the recorder gets a permanent
AUDIOFOCUS_LOSS; noAUDIOFOCUS_GAINfollows while the other app keeps playing, so the recording stays paused. Telling a call (transient) from music (permanent) is exactly what #1358 asks for, but even with that distinction the app has to take focus to hear about calls at all.
Capture doesn't need focus. Since Android 10 (API 29) the system tells an app when its own recording is silenced because something else took the microphone: AudioManager.AudioRecordingCallback → AudioRecordingConfiguration.isClientSilenced(). That is precisely "the recording was interrupted", without touching playback.
Proposal
Two methods on AudioManager, Android 29+ only (no-ops elsewhere):
/**
* Android 29+: emit the existing `interruption` event when the system silences the
* active AudioRecorder's capture (a call, VoIP, the Assistant, another recorder, the
* mic privacy toggle) and when it lets go. Requests no audio focus, so other apps'
* playback is left alone. No-op on iOS, web and Android < 29.
*/
observeRecordingInterruptions(enabled: boolean): void;
/**
* Android 29+: whether the active recorder's capture is silenced right now, or the
* interruption that silenced it is a call that's still in progress. False elsewhere.
*/
isRecordingSilenced(): boolean;
- Events: reuses
interruption({ type: 'began' | 'ended', shouldResume }). Onebeganwhen the recorder's capture becomes silenced (including a recording that starts already silenced), oneendedwithshouldResume: truewhen it's released. No new event types; noAudioEventenum change. - Matching "our" recording: the input stream gets an allocated audio session id, and the listener matches
AudioRecordingConfiguration.getClientAudioSessionId()against the recorder's current stream id on every callback (a disconnect reopens the stream with a new id). A callback without our configuration is "unknown", never "unsilenced". - Calls:
endedis held while the audio mode is a call mode (MODE_IN_CALL,MODE_IN_COMMUNICATION,MODE_CALL_SCREENING) that started afterbegan— viaOnModeChangedListeneron API 31+, polling on 29–30 — so a recording isn't resumed mid-call. A communication mode the host app itself had already set (its own VoIP/SCO) doesn't count. - Lifetime: registered once on the main looper with counted enable/disable; released in
MediaSessionManager.cleanup()on module invalidate. isRecordingSilenced()lets an app refuse its own resume while the mic is taken (otherwise a resume during a call records silence).
Input stream configuration (needs a maintainer decision)
For the system to silence (and later un-silence) our capture rather than disconnect it, the input stream has to stay off MMAP. Today the recorder opens SharingMode::Exclusive (with PerformanceMode::None); an exclusive/MMAP input stream tends to be disconnected when the policy reroutes. We'd propose an opt-in recorder option (e.g. androidSharedInput: true, name open) rather than changing the default, since it can raise input latency for apps that want it low. Two related points from our implementation, happy to split them out:
- AAudio can't pause an input stream (
pause()→ErrorUnimplemented), so the stream keeps running while paused and the data callback drops buffers. A disconnect reclaim must therefore restart the stream even while paused — a stopped stream leaves the active recording configurations, so the end of the interruption is never reported. (Upstream's reclaim was restructured intorestartCapture(); we'd check this there.) - A related bug fix, separate PR: a pause requested while the stream is reconnecting is dropped today (
pause()returns early on!isStreamRecording()), so the recorder keeps writing after the reconnect.
Evidence
Device spike (Pixel 3 XL, Android 12, and an API 34 emulator):
| Case | Silenced vs disconnected | began | ended |
|---|---|---|---|
| Signal (VoIP) call, Pixel | silenced, no disconnect | when the other app opened the mic | within ~10 ms of hang-up |
| Cellular call, emulator | disconnected 1–2× at ring, then silenced | at ring | at hang-up (once the reclaim restarts the stream while paused) |
With the app pausing on began (buffers dropped while paused) and resuming on ended, the saved file excluded the call: 1165.7 s recorded vs 1166.0 s expected for a ~20 min recording with a ~28 s call. Across 12 answered emulator calls the recorded duration never advanced during a call.
Compatibility / scope
- Additive and opt-in;
observeAudioInterruptions(focus) is unchanged and remains the right choice for playback apps. - iOS: no-op — iOS already reports interruptions through the audio session; a mixable
playAndRecordsession gets the same "only mic-takers interrupt" behaviour. - Web: no-op. Old-arch spec, web spec and Jest mock updated.
- Android < 29: no-op (no
isClientSilenced); apps keep using focus there.
Alternatives considered
- Transient vs permanent focus loss (#1358's suggestion): still requires taking focus (so starting a recording stops music), and once focus is lost permanently the app stops hearing later calls.
- Audio-mode / telephony listening only: misses the Assistant, other recorders and the mic privacy toggle; we use the audio mode only to hold
endedduring a call.
Implementation
We run this in production-bound code on our fork (based on 0.13.6): RecordingSilenceListener.kt, the AudioManager API and docs. If the API shape works for you, we'll port it onto main as a PR (including the old-arch spec, web no-op, mock and docs). Related: #1358.
- Lingua principale
- C++
- Stelle
- 864
- Fork
- 103
- Merge medio
- 1g 16h
- PR unite (30g)
- 77
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di software-mansion/react-native-audio-api
-
AudioContext destructor dereferences a null audioPlayer_ when construction fails before initialize()Forse già presa @maciejmakowski2003 l’ha presa 1 giorno fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
software-mansion/react-native-audio-api#1504 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
bug ios
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
software-mansion/react-native-audio-api#1238 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Closed AudioContext / OfflineAudioContext is never released: stateChange listener is never unregisteredForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug
Difficoltà 4/5 1-2 giorni Idoneità per principianti 35/100
software-mansion/react-native-audio-api#1497 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
android bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 20/100
software-mansion/react-native-audio-api#1494 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
DelayNode: signals connected to delayTime are ignored, and delayTime = 0 delays by maxDelayTimeForse già presa @mdydek l’ha presa 6 giorni fa. Apertabug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
software-mansion/react-native-audio-api#1491 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di software-mansion/react-native-audio-api
Issue simili
-
bug good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
difficulty:easy func:gui prio:normal type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NatronGitHub/Natron#2118 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
-
bug difficulty:easy prio:low
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
NatronGitHub/openfx-io#523 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
ArduPilot/ardupilot_gazebo#195 ·