Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 onInitialized seems to be called too early on Android #1053

Closed
3 of 4 tasks
gary-cohen opened this issue May 19, 2022 · 6 comments · Fixed by #1466
Closed
3 of 4 tasks

🐛 onInitialized seems to be called too early on Android #1053

gary-cohen opened this issue May 19, 2022 · 6 comments · Fixed by #1466
Labels
🐛 bug Something isn't working

Comments

@gary-cohen
Copy link

What were you trying to do?

On some Android devices (Google Pixel 2) the camera returns from onInitialized yet doesn't seem ready to capture. If I put a setTimeout of 500ms before allowing takePhoto to be called it helps on the faster devices but not on the Pixel 2. I can continue to tweak the timeout, but I'm hoping you see what the issue could be.

Reproduceable Code

No response

What happened instead?

The camera doesn't take a photo, or when running in Waldo, the screen stays black (see below, the upper row is using react-native-camera and the second row is react-native-vision-camera).
Screen Shot 2022-05-19 at 13 40 05

Relevant log output

No response

Device

Pixel 2, Galaxy S10

VisionCamera Version

2.13.3

Additional information

@gary-cohen gary-cohen added the 🐛 bug Something isn't working label May 19, 2022
@mrousavy
Copy link
Owner

Huh that's interesting, I'm not sure if there is a native event that we need to wait for here:

Log.i(TAG, "Attaching ${useCases.size} use-cases...")
camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview, *useCases.toTypedArray())
preview!!.setSurfaceProvider(previewView.surfaceProvider)
minZoom = camera!!.cameraInfo.zoomState.value?.minZoomRatio ?: 1f
maxZoom = camera!!.cameraInfo.zoomState.value?.maxZoomRatio ?: 1f
val duration = System.currentTimeMillis() - startTime
Log.i(TAG_PERF, "Session configured in $duration ms! Camera: ${camera!!}")
invokeOnInitialized()

@gary-cohen
Copy link
Author

@mrousavy I'm not sure exactly (your code seems to look ok). I did see this which could be useful to know when the preview is streaming (which might be the event we could key off of). https://stackoverflow.com/questions/69401931/android-how-to-get-a-callback-in-camerax-when-the-camera-device-has-finished-op

@gary-cohen
Copy link
Author

@mrousavy just checking up with this... do you think we could get an event with the preview is streaming? I think that will do what I'm looking for.

@mrousavy
Copy link
Owner

mrousavy commented Aug 7, 2022

I think that's implied with a Frame Processor, I'll have a look if that also works if the FP use case is not attached...

@mrousavy
Copy link
Owner

Hey! I've rewritten the entire Android codebase of VisionCamera from CameraX to Camera2 in the efforts of ✨ VisionCamera V3.

I just now completed the Camera2 rewrite and I believe the core structure is running, but there might be some edge cases to iron out. Can you try and test the PR #1674 for me to see if you can still reproduce this issue here?

Here's an instruction on how you can test that: #1674 (comment)

If the issue cannot be reproduced with that version/PR anymore, then hoorayy, I fixed it! 🎉
Otherwise please let me know and I'll keep this issue open to keep track of it.

Thank you!

@gary-cohen
Copy link
Author

Thanks @mrousavy. I'll try to find some time to integrate the new code in the coming days/weeks. Thanks again for all of your work on this. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants