Invalid engine states on recording or playback start#1005
Merged
maciejmakowski2003 merged 22 commits intomainfrom Apr 14, 2026
Merged
Conversation
michalsek
commented
Mar 31, 2026
packages/react-native-audio-api/ios/audioapi/ios/system/AudioSessionManager.mm
Outdated
Show resolved
Hide resolved
packages/react-native-audio-api/ios/audioapi/ios/system/AudioSessionManager.mm
Outdated
Show resolved
Hide resolved
packages/react-native-audio-api/ios/audioapi/ios/system/AudioSessionManager.mm
Show resolved
Hide resolved
packages/react-native-audio-api/ios/audioapi/ios/system/AudioSessionManager.mm
Outdated
Show resolved
Hide resolved
packages/react-native-audio-api/ios/audioapi/ios/system/AudioEngine.mm
Outdated
Show resolved
Hide resolved
packages/react-native-audio-api/ios/audioapi/ios/system/AudioEngine.mm
Outdated
Show resolved
Hide resolved
packages/react-native-audio-api/ios/audioapi/ios/core/NativeAudioPlayer.m
Outdated
Show resolved
Hide resolved
packages/react-native-audio-api/ios/audioapi/ios/core/NativeAudioPlayer.m
Outdated
Show resolved
Hide resolved
packages/react-native-audio-api/ios/audioapi/ios/core/NativeAudioPlayer.m
Outdated
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves iOS audio session / engine state management to prevent invalid states when starting recording or playback, and adds an iOS-focused stress-test screen in the example app to exercise these transitions.
Changes:
- Introduces
AudioSessionManager::ensureActive(force, error)and new input-route helpers to make session activation/configuration more robust. - Refactors
AudioEnginelifecycle (create/destroy/rebuild) and adds handling for explicit session deactivation + better “engine running” checks. - Expands the example app with an “Audio Pipeline Stress” suite and exposes
AudioRecorderHostObject.isPaused()to JS.
Reviewed changes
Copilot reviewed 17 out of 19 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react-native-audio-api/ios/audioapi/ios/system/AudioSessionManager.mm | Adds ensureActive, activation helper, cached-state reset, and input route/format helpers. |
| packages/react-native-audio-api/ios/audioapi/ios/system/AudioSessionManager.h | Exposes ensureActive, input-route/format helpers publicly. |
| packages/react-native-audio-api/ios/audioapi/ios/system/AudioEngine.mm | Adds engine create/destroy, graph rebuild tracking, session-deactivated handler, and running-state helper. |
| packages/react-native-audio-api/ios/audioapi/ios/system/AudioEngine.h | Declares graphNeedsRebuild, onSessionDeactivated, isEngineRunning. |
| packages/react-native-audio-api/ios/audioapi/ios/core/NativeAudioRecorder.m | Uses getPreferredInputFormat fallback when engine format is invalid. |
| packages/react-native-audio-api/ios/audioapi/ios/core/NativeAudioPlayer.m | Forces session activation for playback and makes source-node attach/detach idempotent. |
| packages/react-native-audio-api/ios/audioapi/ios/core/IOSAudioRecorder.mm | Forces session activation for recording and errors early if input route/format isn’t usable. |
| packages/react-native-audio-api/ios/audioapi/ios/core/IOSAudioPlayer.mm | Tightens “is playing” check to include underlying engine running state. |
| packages/react-native-audio-api/ios/audioapi/ios/AudioAPIModule.mm | On session deactivation, clears cached session active state and updates engine state. |
| packages/react-native-audio-api/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp | Exports isPaused() to JS. |
| packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp | Formatting-only change around NOLINT placement. |
| packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletProcessingNode.cpp | Adds missing <algorithm> include. |
| apps/fabric-example/ios/Podfile.lock | Updates CocoaPods lockfile checksums. |
| apps/fabric-example/ios/FabricExample/Info.plist | Whitespace/indentation cleanup. |
| apps/fabric-example/ios/FabricExample.xcodeproj/project.pbxproj | Project config changes (signing team, bundle id, build phase metadata). |
| apps/common-app/src/examples/index.ts | Registers the new AudioPipelineStress example screen. |
| apps/common-app/src/examples/AudioPipelineStress/index.ts | Re-exports the new screen component. |
| apps/common-app/src/examples/AudioPipelineStress/AudioPipelineStress.tsx | Adds an iOS-only automated stress suite UI for record/playback + session toggling scenarios. |
| apps/common-app/src/examples/AudioFile/AudioPlayer.ts | Removes unused import and improves formatting for readability. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/react-native-audio-api/ios/audioapi/ios/system/AudioSessionManager.mm
Show resolved
Hide resolved
apps/fabric-example/ios/FabricExample.xcodeproj/project.pbxproj
Outdated
Show resolved
Hide resolved
apps/fabric-example/ios/FabricExample.xcodeproj/project.pbxproj
Outdated
Show resolved
Hide resolved
apps/common-app/src/examples/AudioPipelineStress/AudioPipelineStress.tsx
Show resolved
Hide resolved
7 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 58 out of 63 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (1)
apps/common-app/src/demos/Record/Record.tsx:130
Recorder.stop()returnspaths: string[], which can legally be empty even on success (see other call sites that guard for this). Accessinginfo.paths[0]without a length check can passundefinedintodecodeAudioData, causing a runtime error. Please guard for an emptypathsarray and surface a user-facing error.
const onStopRecording = useCallback(async () => {
const info = Recorder.stop();
RecordingNotificationManager.hide();
setState(RecordingState.Loading);
if (info.status !== 'success') {
Alert.alert('Error', `Failed to stop recording: ${info.message}`);
setRecordedBuffer(null);
setState(RecordingState.Idle);
return;
}
const audioBuffer = await audioContext.decodeAudioData(info.paths[0]);
setRecordedBuffer(audioBuffer);
setState(RecordingState.ReadyToPlay);
currentPositionSV.value = 0;
}, []);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/react-native-audio-api/ios/audioapi/ios/core/IOSAudioRecorder.mm
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1004
Closes RNAA-407
Closes RNAA-382
Introduced changes
isPausedin AudioRecorder JSI interface.Checklist