camera-preview
camera-preview copied to clipboard
Camera preview takes time to open in ios after capacitor 3 upgrade
Describe the bug I have been using this plugin for a while, but recently we upgraded from capacitor 2 to 3 and upgraded the plugin to v3 and while things work as usual in android, we have been experiencing some delay while opening the camera preview in ios. Specifically, on clicking on the camera cta, we see a black screen for a while and then the camera preview opens after about 2-4 seconds. I've tested this on iphone 6(ios 12) and iphone XR(ios 15) and facing this issue in both the devices. And like I said things work fine on android devices
Hi @yksolanki9 how slow was the camera startup on iOS with Capacitor 2? It's always felt slow for me on iOS but not in the 2+ seconds range. I've never worked out why there's the delay on iOS, but it does need to be resolved.
For capacitor 2, there was no noticable lag in opening the camera preview. But since upgrading to capacitor 3 and plugin v3, the delay has increased considerably
Hi, any news on this topic ? I experience the same issue as described : the camera preview takes more than 2 seconds to open on IOS only. Tested on Iphone SE (ios15) and Iphone 15 (ios15).
Since I have the same problem, I did some debugging on this issue. It seems to be related to AVCaptureSession in the file CameraController, especially when calling startRunning() and doing some stuff in func configureDataOutput().
Looking into the Apple documentation, I found information about this issue: https://developer.apple.com/documentation/avfoundation/avcapturesession
This page says:
Important
The startRunning() method is a blocking call which can take some time, therefore start the session on a serial dispatch queue so that you don’t block the main queue (which keeps the UI responsive). See AVCam: Building a Camera App for an implementation example.
I don't know anything about Swift, so I don't know how to make the appropriate changes in order to make this work with a serial dispatch queue. One thing I do know is that the current code does not use the serial dispatch queue.
Hopefully someone with Swift knowledge can look further into this issue.
I dived further into the code and noticed that some dispatching is already taking place, but all logic is handled in one dispatch queue (DispatchQueue(label: "prepare").async).
I added some code to measure the duration of specific functions. These are the results:
Time elapsed for configureCaptureDevices: 0.01330411434173584 s. Time elapsed for configureDeviceInputs: 0.003573894500732422 s. Time elapsed for configurePhotoOutput: 0.5769590139389038 s. Time elapsed for configureDataOutput: 0.3801349401473999 s. Time elapsed for updateVideoOrientation: 0.45588791370391846 s.
When adding all the timestamps, the total time is about 1.5 seconds to execute. Is it possible to make this code run concurrently to bring down the time, maybe by adding a few extra dispatchQueues?
Anyone here who can investigate this further?
@Sparkfield it takes 1.6s on iPhone 11 and ~2.5s on iPhone 13 and ~4s on iPhone 14. I have no experience in Swift but I did the same as you did. I hope anyone can help with this.
Im having the same problem on iOS. Preview takes around 2 seconds to load every time, it's causing quite an issue. Can anyone please help?