mrousavy / react-native-vision-camera

📸 A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
7.55k stars 1.1k forks source link

✨ Enable multitasking camera access on iOS #3210

Closed ethul closed 2 weeks ago

ethul commented 1 month ago

What feature or enhancement are you suggesting?

Would it be possible to add support for enabling multitasking camera access?

This would be useful for apps running on iPads with Stage Manager or Split View/Slide Over turned on.

From the Apple developer documentation I tried adding the following to the camera session, which seemed to do the trick.

if #available(iOS 16.0, *) {
  if self.captureSession.isMultitaskingCameraAccessSupported {
    // Enable use of the camera in multitasking modes.
    self.captureSession.isMultitaskingCameraAccessEnabled = true
  }
}

What Platforms whould this feature/enhancement affect?

iOS

Alternatives/Workarounds

I manually made the change in Core/CameraSession.swift.

Additional information

maintenance-hans[bot] commented 1 month ago

Guten Tag, Hans here! 🍻

Zis feature request for enabling multitasking camera access on iOS is interesting, and it looks like you already made some attempts! However, we need a bit more information to evaluate zis properly. It would be helpful if you could provide any logs or error messages you encountered while implementing zis feature.

Also, if you appreciate ze work we do on zis repository, consider sponsoring the project to help us keep it going! Support mrousavy on GitHub Sponsors.

Let's keep ze conversation going!

Note: If you think I made a mistake, please ping @mrousavy to take a look.

ethul commented 1 month ago

Without the change to enable multitasking, when Stage Manager or Split View/Slide Over was turned on, the camera preview was blank, and recording a video issued an error:

capture/unknown: Error Domain=AVFoundationErrorDomain Code=-11803 "Cannot Record" UserInfo={AVErrorRecordingFailureDomainKey=3, NSLocalizedDescription=Cannot Record, NSLocalizedRecoverySuggestion=Try recording again.}
mrousavy commented 1 month ago

Hey! Oh, pretty cool. Yea I can add that feature if I have some free time soon, thanks for posting the code here this is really helpful.

ethul commented 1 month ago

Great, thanks!

ChristopherGabba commented 2 weeks ago

+1 on this, I have CameraRuntimeError's every now and then when another task interrupts the camera. Not 100% sure if this would fix the problem, but it couldn't hurt! Sometimes, this also creates a video recording with no audio when another video in the background hijacks the audio session.

mrousavy commented 2 weeks ago

Reading the docs wouldn't hurt - this is already true if you have the entitlement for it (which is required, and would crash otherwise)

Screenshot 2024-10-29 at 09 23 56

ethul commented 1 week ago

I think it is important to note that the multitaasking-camera-access entitlement is deprecated.

Screen Shot 2024-10-30 at 10 27 50 AM

It seems like the recommended approach is to use isMultitaskingCameraAccessEnabled.