Skip to content

feat(ios): expose custom audio session control#3804

Open
Aniketiitk21 wants to merge 1 commit intomrousavy:mainfrom
Aniketiitk21:ios-custom-audio-session-control
Open

feat(ios): expose custom audio session control#3804
Aniketiitk21 wants to merge 1 commit intomrousavy:mainfrom
Aniketiitk21:ios-custom-audio-session-control

Conversation

@Aniketiitk21
Copy link
Copy Markdown

Summary

  • expose automaticallyConfiguresApplicationAudioSession on CameraSessionConfiguration and the public useCamera() / <Camera /> API
  • surface the existing allowBackgroundAudioPlayback session option on the public React API
  • apply the audio-session setting to both iOS recording paths, including the persistent recorder's dedicated audio capture session
  • document how to keep background audio playing or hand AVAudioSession control to another library such as react-native-volume-manager
  • regenerate the Nitro bridge for the updated session config shape

Why

Issue #2581 asks for more customized audio control, especially for apps that behave more like FaceTime where media playback and microphone capture need to coexist.

The most important missing piece today is that VisionCamera's iOS capture sessions still own application-level audio-session behavior, while apps have no supported way to tell VisionCamera to stop auto-configuring AVAudioSession. That makes it hard to use custom videoChat, voiceChat, or measurement modes through another native integration, and it blocks the exact disableAudioSession style escape hatch requested in the issue.

This change adds that escape hatch while also exposing the already-implemented background-audio-mixing flag on the public React API.

Implementation

  • add automaticallyConfiguresApplicationAudioSession?: boolean to CameraSessionConfiguration
  • thread the new session setting through useCameraController() and useCamera() / <Camera />
  • on iOS, set AVCaptureSession.automaticallyConfiguresApplicationAudioSession on the main HybridCameraSession
  • keep configuresApplicationAudioSessionToMixWithOthers in sync when VisionCamera is still managing the app audio session
  • extend NativeCameraOutput with a session-aware configure hook so outputs that need session-wide state can opt in without changing every output implementation
  • make the persistent recorder's separate AudioSession respect the same audio-session-management setting and background-audio-mixing flag
  • update the video docs with examples for:
    • continuing already-playing audio during recording
    • disabling automatic app audio-session management to let another library control AVAudioSession

Behavior

  • by default, behavior stays the same: iOS capture sessions continue to auto-configure the app audio session
  • setting automaticallyConfiguresApplicationAudioSession: false tells VisionCamera to stop auto-managing the app audio session on iOS
  • with automatic management disabled, apps can configure AVAudioSession themselves through another native module
  • allowBackgroundAudioPlayback is now reachable from the public React API and continues to work when VisionCamera is managing the app audio session
  • the persistent recorder now follows the same policy as the main camera session instead of silently re-enabling automatic app audio-session management

Testing

  • npm run typecheck
  • tsc --noEmit false && nitrogen
  • .\gradlew.bat :react-native-vision-camera:compileDebugKotlin --no-daemon --console=plain

Notes

  • this change is implemented for iOS, because the issue's requested AVAudioSession escape hatch is iOS-specific
  • the new API is intentionally session-scoped so both the normal recorder and persistent recorder can stay aligned

Closes #2581

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 26, 2026

@Aniketiitk21 is attempting to deploy a commit to the Margelo Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ More Customized Audio Control

1 participant