Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
2c35596
fix: issue #1220 suggested onInterruptionEnd update
SomePersonFromMars Aug 20, 2026
0547b09
fix: minor tweaks to previous flawed patch
SomePersonFromMars Aug 24, 2026
b9fd96e
fix: add mixWithOthers to Recorder demo
SomePersonFromMars Aug 27, 2026
b93c5c1
fix: generalize handleInputConfigurationChange() to handle errors
SomePersonFromMars Aug 27, 2026
523e5a4
fix: retry AudioEngine resume from interrupt when back foreground
SomePersonFromMars Aug 27, 2026
1bfa489
fix: reopen a new rotating segment after capture loss instead of rota…
SomePersonFromMars Aug 27, 2026
6283fb7
fix: retry AudioEngine resume only happens when interruption ended wa…
SomePersonFromMars Aug 28, 2026
bc74d58
fix: always perform native recovery after interruption notification
SomePersonFromMars Aug 31, 2026
f12b250
feat: observeAudioInterruptions(true) in the Record demo
SomePersonFromMars Aug 31, 2026
86a9ae7
feat: document resuming recording after an interruption
SomePersonFromMars Sep 2, 2026
673d326
fix: detach source node in player on failed start similarly to what r…
SomePersonFromMars Sep 2, 2026
d648901
fix: don't poison state on a no-op deactivation
SomePersonFromMars Sep 3, 2026
33c3753
fix: recorder resume() only updates state on successful engine start
SomePersonFromMars Sep 3, 2026
bcadbb3
Merge branch 'main' into fix/ios-recording-interrupted
SomePersonFromMars Sep 17, 2026
32c2906
Merge branch 'main' into fix/ios-recording-interrupted
SomePersonFromMars Sep 17, 2026
6b17b0f
fix: workaround to mitigate infinite loop when starting recording
SomePersonFromMars Sep 18, 2026
d9268b3
fix: schedule rebuild on configuration change instead of doing it int…
SomePersonFromMars Sep 18, 2026
3249d2d
Merge branch 'main' into fix/ios-recording-interrupted
SomePersonFromMars Sep 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ if (status !== 'Granted') return;

### Interruption handling

Enable emission with `AudioManager.observeAudioInterruptions(true)`, then listen.

**Playback:** pause on `began` (native does not resume players). The AudioFile example resumes on `ended` when it had been playing.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Playback:** pause on `began` (native does not resume players). The AudioFile example resumes on `ended` when it had been playing.
**Playback:** native pause on `began`, but does not resume any audio contexts. The AudioFile example resumes on `ended` when it had been playing.


```tsx
useEffect(() => {
const sub = AudioManager.addSystemEventListener('interruption', (event) => {
Expand All @@ -290,6 +294,8 @@ useEffect(() => {
}, []);
```

**Recording:** native always resumes the engine. Do not `Recorder.pause()` on `began`. iOS has already stopped I/O; the engine is `Interrupted`, not `Paused`. Only `Interrupted` is retried on `ended` / foreground — `Recorder.pause()` would move the engine to `Paused` and disable that retry. JS only freezes UI that still looks live (the Record demo's scrolling waveform). Unfreeze only on `ended` (failed resume does not emit `ended`).

## Shared UI Components

All in `apps/common-app/src/components/`:
Expand Down
38 changes: 36 additions & 2 deletions apps/common-app/src/demos/Record/Record.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ const Record: FC = () => {
: RecordingState.Recording;
});
const [hasPermissions, setHasPermissions] = useState<boolean>(false);
const [isInterrupted, setIsInterrupted] = useState(false);
const [recordedBuffer, setRecordedBuffer] = useState<AudioBuffer | null>(
null
);
const currentPositionSV = useSharedValue(0);
const playbackSourceRef = useRef<AudioBufferSourceNode | null>(null);
const stateRef = useRef(state);

const stopPlayback = useCallback(() => {
const source = playbackSourceRef.current;
Expand Down Expand Up @@ -88,7 +90,7 @@ const Record: FC = () => {
AudioManager.setAudioSessionOptions({
iosCategory: 'playAndRecord',
iosMode: 'default',
iosOptions: ['defaultToSpeaker', 'allowBluetoothA2DP'],
iosOptions: ['defaultToSpeaker', 'allowBluetoothA2DP', 'mixWithOthers'],
});

try {
Expand All @@ -107,6 +109,7 @@ const Record: FC = () => {
setupNotification(false);

if (result.status === 'success') {
setIsInterrupted(false);
setState(RecordingState.Recording);
return;
}
Expand All @@ -119,6 +122,7 @@ const Record: FC = () => {
const onPauseRecording = useCallback(() => {
Recorder.pause();
updateNotification(true);
setIsInterrupted(false);
setState(RecordingState.Paused);
}, []);

Expand Down Expand Up @@ -152,6 +156,7 @@ const Record: FC = () => {
const onStopRecording = useCallback(async () => {
const info = await Recorder.stop();
RecordingNotificationManager.hide();
setIsInterrupted(false);
setState(RecordingState.Loading);

if (info.status !== 'success') {
Expand Down Expand Up @@ -263,6 +268,10 @@ const Record: FC = () => {
]
);

useEffect(() => {
stateRef.current = state;
}, [state]);

useEffect(() => {
(async () => {
const recordingPermissionStatus =
Expand All @@ -283,6 +292,31 @@ const Record: FC = () => {
})();
}, []);

useEffect(() => {
AudioManager.observeAudioInterruptions(true);

const interruptionSubscription = AudioManager.addSystemEventListener(
'interruption',
(event) => {
if (event.type === 'began') {
if (stateRef.current === RecordingState.Recording) {
setIsInterrupted(true);
}
return;
}

if (event.type === 'ended') {
setIsInterrupted(false);
}
}
);

return () => {
interruptionSubscription.remove();
AudioManager.observeAudioInterruptions(false);
};
}, []);

useEffect(() => {
const pauseListener = RecordingNotificationManager.addEventListener(
'recordingNotificationPause',
Expand Down Expand Up @@ -357,7 +391,7 @@ const Record: FC = () => {
<>
<RecordingTime state={state} />
<View style={styles.spacerS} />
<RecordingVisualization state={state} />
<RecordingVisualization state={state} isInterrupted={isInterrupted} />
</>
)}
<View style={styles.spacerM} />
Expand Down
Loading
Loading