Matthias Nott
2026-03-07 8cdf33e27c633ac30e8851c4617f6063c141660d
services/audio.ts
....@@ -11,6 +11,22 @@
1111 durationMs: number;
1212 }
1313
14
+// --- Audio mode (set once at import time) ---
15
+// Setting this on every playback causes iOS to renegotiate the audio route,
16
+// which disconnects Bluetooth/CarPlay. Set it once and leave it alone.
17
+let _audioModeReady = false;
18
+async function ensureAudioMode(): Promise<void> {
19
+ if (_audioModeReady) return;
20
+ _audioModeReady = true;
21
+ try {
22
+ await setAudioModeAsync({ playsInSilentMode: true });
23
+ } catch {
24
+ _audioModeReady = false; // retry next time
25
+ }
26
+}
27
+// Eagerly initialize on module load
28
+ensureAudioMode();
29
+
1430 // --- Autoplay suppression ---
1531 // Don't autoplay voice messages when the app is in the background
1632 // or when the user is on a phone call (detected via audio interruption).
....@@ -153,7 +169,7 @@
153169 let player: ReturnType<typeof createAudioPlayer> | null = null;
154170
155171 try {
156
- await setAudioModeAsync({ playsInSilentMode: true });
172
+ await ensureAudioMode();
157173
158174 player = createAudioPlayer(uri);
159175 currentPlayer = player;