[Android] Recording interruptions without audio focus (observeRecordingInterruptions / isRecordingSilenced)

オープン
#1,388 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@JaydeepAgravat がすでに取り組んでいます。

2026年11月21日 から。

  • #1488 @JaydeepAgravat による — オープン

評価

難易度
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 の本文から書いたものです。

説明

android feature-request
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:

  1. Starting a recording stops the user's music. AUDIOFOCUS_GAIN makes 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.
  2. Other apps' playback pauses the recording, and it never comes back. When the user starts music, the recorder gets a permanent AUDIOFOCUS_LOSS; no AUDIOFOCUS_GAIN follows 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 }). One began when the recorder's capture becomes silenced (including a recording that starts already silenced), one ended with shouldResume: true when it's released. No new event types; no AudioEvent enum 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: ended is held while the audio mode is a call mode (MODE_IN_CALL, MODE_IN_COMMUNICATION, MODE_CALL_SCREENING) that started after began — via OnModeChangedListener on 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 into restartCapture(); 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 playAndRecord session 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 ended during 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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

software-mansion/react-native-audio-api のほかの issue

software-mansion/react-native-audio-api の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。