Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Android: audio focus listener posts to a dead looper after JS reload, interruptions (calls) are missed

Aperta Adatta ai principianti
#1,358 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
android, kotlin, react-native

Direzione di ricerca

Individua l’implementazione Android di AudioFocusListener.requestAudioFocus e verifica come viene registrato il listener per i cambiamenti del focus audio. Inizia tracciando il builder della richiesta e il percorso della callback attraverso callInvoker; verifica che i cambiamenti del focus continuino a generare eventi di interruzione dopo un reload di JS. Il lavoro è completato quando il listener usa un looper attivo e lo scenario di chiamata segnalato non perde più l’evento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

android bug

Description

On Android, AudioManager.observeAudioInterruptions(true) stops delivering interruption events after a JS reload: focus changes reach the app process but are posted to a dead looper.

W MessageQueue: java.lang.IllegalStateException: Handler (android.media.AudioManager$ServiceEventHandlerDelegate$1) {…} sending message to a Handler on a dead thread
W MessageQueue:   at android.media.AudioManager$1.dispatchAudioFocusChange(AudioManager.java:4370)

In our case an incoming phone call (and a WhatsApp call) during a recording was not detected: no began event, the recorder kept running and wrote silence.

Cause

AudioFocusListener.requestAudioFocus builds the request with setOnAudioFocusChangeListener(this) and no handler. Android then dispatches callbacks on the looper of the thread that created the process-wide AudioManager (ServiceEventHandlerDelegate(null) uses Looper.myLooper()), here the JS thread. After a reload that thread is gone, so every later focus change is dropped.

Steps to reproduce

  1. Dev build, call AudioManager.observeAudioInterruptions(true) and start an AudioRecorder.
  2. Reload JS (dev menu or Fast Refresh full reload), start recording again.
  3. Call the device. No interruption event; logcat shows the exception above. After a cold start, the same call is detected (onAudioFocusChange: -2 within ~20 ms).

Suggested fix

Pass the main looper explicitly:

AudioFocusRequest
  .Builder(focus)
  .setOnAudioFocusChangeListener(this, Handler(Looper.getMainLooper()))
  .build()

Events still reach JS through callInvoker, so dispatching from the main thread is safe. We ship this as a local patch and can open a PR if useful.

Related suggestion: the began payload does not say whether the loss is transient (AUDIOFOCUS_LOSS_TRANSIENT, e.g. a call or ringtone, followed by a gain) or permanent (AUDIOFOCUS_LOSS). Apps that should not offer "resume" while a call holds the mic need that distinction; we currently report it through shouldResume: true on transient began.

Environment

  • react-native-audio-api 0.13.6, React Native 0.88 (new architecture, bridgeless), Expo SDK 58 dev client
  • Samsung Galaxy A05 (SM-A055F), Android 14
Lingua principale
C++
Stelle
852
Fork
97
Merge medio
4g 6h
PR unite (30g)
20

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di software-mansion/react-native-audio-api

Tutte le issue di software-mansion/react-native-audio-api

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.