[Android] Recording interruptions without audio focus (observeRecordingInterruptions / isRecordingSilenced)
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 15/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- android, cpp, kotlin, react-native, typescript
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- C++
- スター
- 864
- フォーク
- 103
- 平均マージ
- 1日 16時間
- マージ済み PR(30日)
- 77
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
software-mansion/react-native-audio-api のほかの issue
-
AudioContext destructor dereferences a null audioPlayer_ when construction fails before initialize()対応中かも @maciejmakowski2003 が 1 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
software-mansion/react-native-audio-api#1504 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
bug ios
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
software-mansion/react-native-audio-api#1238 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Closed AudioContext / OfflineAudioContext is never released: stateChange listener is never unregistered対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンbug
難易度 4/5 1〜2日 初心者へのやさしさ 35/100
software-mansion/react-native-audio-api#1497 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
android bug
難易度 4/5 3〜5日 初心者へのやさしさ 20/100
software-mansion/react-native-audio-api#1494 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
DelayNode: signals connected to delayTime are ignored, and delayTime = 0 delays by maxDelayTime対応中かも @mdydek が 6 日前に担当しました。 オープンbug
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
software-mansion/react-native-audio-api#1491 ·
メンテナーはふだん 1 日以内に返信
software-mansion/react-native-audio-api の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
riscv-software-src/riscv-isa-sim#2640 ·
メンテナーはふだん 1 日以内に返信
-
bug good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
difficulty:easy func:gui prio:normal type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
NatronGitHub/Natron#2118 ·
メンテナーはふだん 1 日以内に返信
-
Bug
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
-
mechanics UI
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
endless-sky/endless-sky#12949 ·
メンテナーはふだん 1 日以内に返信