[Android] Recording interruptions without audio focus (observeRecordingInterruptions / isRecordingSilenced)
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 15/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- android, cpp, kotlin, react-native, typescript
- Área
- audio-video-rtc, mobile
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- C++
- Estrellas
- 864
- Forks
- 103
- Merge medio
- 1 d 16 h
- PR fusionados (30 d)
- 77
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de software-mansion/react-native-audio-api
-
AudioContext destructor dereferences a null audioPlayer_ when construction fails before initialize()Posiblemente ocupada @maciejmakowski2003 la tomó hace 1 día. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
software-mansion/react-native-audio-api#1504 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
bug ios
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
software-mansion/react-native-audio-api#1238 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Closed AudioContext / OfflineAudioContext is never released: stateChange listener is never unregisteredPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertobug
Dificultad 4/5 1-2 días Aptitud para principiantes 35/100
software-mansion/react-native-audio-api#1497 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
android bug
Dificultad 4/5 3-5 días Aptitud para principiantes 20/100
software-mansion/react-native-audio-api#1494 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
DelayNode: signals connected to delayTime are ignored, and delayTime = 0 delays by maxDelayTimePosiblemente ocupada @mdydek la tomó hace 6 días. Abiertobug
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
software-mansion/react-native-audio-api#1491 ·
Los mantenedores suelen responder en 1 día
Todos los issues de software-mansion/react-native-audio-api
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
riscv-software-src/riscv-isa-sim#2640 ·
Los mantenedores suelen responder en 1 día
-
bug good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
difficulty:easy func:gui prio:normal type:bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NatronGitHub/Natron#2118 ·
Los mantenedores suelen responder en 1 día
-
Bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
-
mechanics UI
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
endless-sky/endless-sky#12949 ·
Los mantenedores suelen responder en 1 día