You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to take a picture, show it and if something is not detected restore the camera.
Reproduceable Code
exportdefault()=>{constnavigation=useNavigation<any>();constcamera=useRef<Camera>(null);constisFocused=useIsFocused();const{hasPermission, requestPermission}=useCameraPermission();const[isInitialized,setIsInitialized]=useState(false);const[isTakingPhoto,setIsTakingPhoto]=useState(false);const[photoUri,setPhotoUri]=useState<string|null>(null);constdevice=useCameraDevice('back');useEffect(()=>{if(!hasPermission){requestPermission();}},[hasPermission,requestPermission]);consttakePhoto=async()=>{if(isInitialized&&camera.current){try{setIsTakingPhoto(true);constfile=awaitcamera.current.takePhoto();setPhotoUri(`file://${file.path}`);// if photo match, navigate away, otherwise throw error}catch(e){setIsTakingPhoto(false);console.error(e);}}};if(isTakingPhoto&&photoUri!==null){return(<><Imagesource={{uri: photoUri}}style={{flex: 1}}/><ActivityIndicator/></>);}returndevice!==undefined&&hasPermission ? (<><Cameraref={camera}onInitialized={()=>setIsInitialized(true)}onStopped={()=>console.error('Camera stopped')}onPreviewStopped={()=>console.error('Camera preview stopped')}style={[StyleSheet.absoluteFill]}device={device}isActive={isFocused}photo={true}photoQualityBalance="speed"/><Viewstyle={styles.buttonContainer}><ButtononPress={takePhoto}style={styles.button}><View/></Button></View></>) : (<CardonPress={()=>Linking.openSettings()}><Card.Content><Textstyle={styles.settingsTextColor}variant="titleLarge">
No permissions, go to settings
</Text></Card.Content></Card>);};
Relevant log output
2025-03-04 18:29:41.452 28022-28119 Camera2CameraImpl com.parkingless.develop D {Camera@7daa75[id=0]} Resetting Capture Session
2025-03-04 18:29:41.453 28022-28022 DeferrableSurface com.parkingless.develop D Surface terminated[total_surfaces=2, used_surfaces=2](androidx.camera.core.processing.SurfaceEdge$SettableSurface@f2197c5}
2025-03-04 18:29:41.453 28022-28022 DeferrableSurface com.parkingless.develop D use count-1, useCount=1 closed=true androidx.camera.core.SurfaceRequest$2@688eb41
2025-03-04 18:29:41.453 28022-28119 SyncCaptureSessionImpl com.parkingless.develop D [androidx.camera.camera2.internal.SynchronizedCaptureSessionImpl@bf33993] Session call close()
2025-03-04 18:29:41.454 28022-29046 System.err com.parkingless.develop W androidx.camera.core.ImageCaptureException: Camera is closed.
2025-03-04 18:29:41.455 28022-29046 System.err com.parkingless.develop W at androidx.camera.core.imagecapture.TakePictureManagerImpl.abortRequests(TakePictureManagerImpl.java:164)
2025-03-04 18:29:41.455 28022-29046 System.err com.parkingless.develop W at androidx.camera.core.ImageCapture.abortImageCaptureRequests(ImageCapture.java:1127)
2025-03-04 18:29:41.455 28022-29046 System.err com.parkingless.develop W at androidx.camera.core.ImageCapture.onStateDetached(ImageCapture.java:1116)
2025-03-04 18:29:41.455 28022-29046 System.err com.parkingless.develop W at androidx.camera.camera2.internal.Camera2CameraImpl.notifyStateDetachedToUseCases(Camera2CameraImpl.java:1060)
2025-03-04 18:29:41.455 28022-29046 System.err com.parkingless.develop W at androidx.camera.camera2.internal.Camera2CameraImpl.detachUseCases(Camera2CameraImpl.java:1079)
2025-03-04 18:29:41.455 28022-29046 System.err com.parkingless.develop W at androidx.camera.core.internal.CameraUseCaseAdapter.detachUseCases(CameraUseCaseAdapter.java:762)
2025-03-04 18:29:41.455 28022-29046 System.err com.parkingless.develop W at androidx.camera.lifecycle.LifecycleCamera.onStop(LifecycleCamera.java:99)
2025-03-04 18:29:41.456 28022-29046 System.err com.parkingless.develop W at androidx.camera.lifecycle.LifecycleCamera.suspend(LifecycleCamera.java:142)
2025-03-04 18:29:41.456 28022-29046 System.err com.parkingless.develop W at androidx.camera.lifecycle.LifecycleCameraRepository.suspendUseCases(LifecycleCameraRepository.java:501)
2025-03-04 18:29:41.456 28022-29046 System.err com.parkingless.develop W at androidx.camera.lifecycle.LifecycleCameraRepository.setInactive(LifecycleCameraRepository.java:446)
2025-03-04 18:29:41.456 28022-28119 Camera2CameraImpl com.parkingless.develop D {Camera@7daa75[id=0]} Releasing session in state OPENED
2025-03-04 18:29:41.456 28022-29046 System.err com.parkingless.develop W at androidx.camera.lifecycle.LifecycleCameraRepository$LifecycleCameraRepositoryObserver.onStop(LifecycleCameraRepository.java:575)
2025-03-04 18:29:41.456 28022-28183 BufferQueueProducer com.parkingless.develop E [SurfaceView[com.parkingless.develop/com.parkingless.MainActivity]#22(BLAST Consumer)22](id:6d7600000023,api:4,p:1586,c:28022) queueBuffer: BufferQueue has been abandoned
2025-03-04 18:29:41.456 28022-28022 ScreenFlashWrapper com.parkingless.develop W completePendingScreenFlashClear: none pending!
2025-03-04 18:29:41.456 28022-28119 Camera2CameraControlImp com.parkingless.develop D setActive: isActive =false
2025-03-04 18:29:41.456 28022-29046 System.err com.parkingless.develop W at java.lang.reflect.Method.invoke(Native Method)
2025-03-04 18:29:41.456 28022-29046 System.err com.parkingless.develop W at androidx.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:225)
2025-03-04 18:29:41.456 28022-29046 System.err com.parkingless.develop W at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeMethodsForEvent(ClassesInfoCache.java:199)
2025-03-04 18:29:41.456 28022-28119 UseCaseAttachState com.parkingless.develop D Active and attached use case: [] for camera: 0
2025-03-04 18:29:41.456 28022-28022 ImageCapture com.parkingless.develop D clearPipeline
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeCallbacks(ClassesInfoCache.java:190)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at androidx.lifecycle.ReflectiveGenericLifecycleObserver.onStateChanged(ReflectiveGenericLifecycleObserver.java:40)
2025-03-04 18:29:41.457 28022-28022 DeferrableSurface com.parkingless.develop D surface closed, useCount=1 closed=true androidx.camera.core.impl.ImmediateSurface@41b05c3
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:360)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at androidx.lifecycle.LifecycleRegistry.backwardPass(LifecycleRegistry.java:290)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:308)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:151)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at androidx.lifecycle.LifecycleRegistry.setCurrentState(LifecycleRegistry.java:121)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at com.mrousavy.camera.core.CameraSession.close(CameraSession.kt:89)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at com.mrousavy.camera.react.CameraView.destroy(CameraView.kt:148)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at com.mrousavy.camera.react.CameraViewManager.onDropViewInstance(CameraViewManager.kt:49)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at com.mrousavy.camera.react.CameraViewManager.onDropViewInstance(CameraViewManager.kt:18)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at com.facebook.react.uimanager.NativeViewHierarchyManager.dropView(NativeViewHierarchyManager.java:630)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java:495)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute(UIViewOperationQueue.java:183)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:851)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:964)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at com.facebook.react.uimanager.UIViewOperationQueue.-$$Nest$mflushPendingBatches(Unknown Source:0)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:1024)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.kt:22)
2025-03-04 18:29:41.457 28022-29046 System.err com.parkingless.develop W at com.facebook.react.modules.core.ReactChoreographer$1.doFrame(ReactChoreographer.java:89)
2025-03-04 18:29:41.457 28022-28022 CameraSession com.parkingless.develop I Camera Lifecycle changed to STARTED!
2025-03-04 18:29:41.458 28022-29046 System.err com.parkingless.develop W at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1158)
2025-03-04 18:29:41.458 28022-28022 CameraSession com.parkingless.develop I Camera Lifecycle changed to CREATED!
2025-03-04 18:29:41.458 28022-28022 CameraSession com.parkingless.develop I Camera Lifecycle changed to DESTROYED!
2025-03-04 18:29:41.458 28022-28038 BufferQueueProducer com.parkingless.develop E [SurfaceView[com.parkingless.develop/com.parkingless.MainActivity]#22(BLAST Consumer)22](id:6d7600000023,api:4,p:1586,c:28022) dequeueBuffer: BufferQueue has been abandoned
2025-03-04 18:29:41.458 28022-28038 CameraDevice-JV-0 com.parkingless.develop W Device error received, code 3, frame number 29, request ID 1, subseq ID 0
2025-03-04 18:29:41.459 28022-28038 CameraDevice-JV-0 com.parkingless.develop W got error frame 29
2025-03-04 18:29:41.459 28022-28038 CameraDevice-JV-0 com.parkingless.develop W Repeating request error received. Last frame number is 29
2025-03-04 18:29:41.459 28022-29046 System.err com.parkingless.develop W at android.view.Choreographer.doCallbacks(Choreographer.java:950)
2025-03-04 18:29:41.459 28022-28119 UseCaseAttachState com.parkingless.develop D Active and attached use case: [] for camera: 0
2025-03-04 18:29:41.459 28022-29046 System.err com.parkingless.develop W at android.view.Choreographer.doFrame(Choreographer.java:874)
2025-03-04 18:29:41.459 28022-29046 System.err com.parkingless.develop W at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1142)
2025-03-04 18:29:41.459 28022-29046 System.err com.parkingless.develop W at android.os.Handler.handleCallback(Handler.java:938)
2025-03-04 18:29:41.460 28022-29046 System.err com.parkingless.develop W at android.os.Handler.dispatchMessage(Handler.java:99)
2025-03-04 18:29:41.460 28022-29046 System.err com.parkingless.develop W at android.os.Looper.loopOnce(Looper.java:210)
2025-03-04 18:29:41.460 28022-29046 System.err com.parkingless.develop W at android.os.Looper.loop(Looper.java:299)
2025-03-04 18:29:41.460 28022-29046 System.err com.parkingless.develop W at android.app.ActivityThread.main(ActivityThread.java:8319)
2025-03-04 18:29:41.460 28022-29046 System.err com.parkingless.develop W at java.lang.reflect.Method.invoke(Native Method)
2025-03-04 18:29:41.460 28022-29046 System.err com.parkingless.develop W at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
2025-03-04 18:29:41.460 28022-29046 System.err com.parkingless.develop W at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1038)
2025-03-04 18:29:41.460 28022-28119 VideoUsageControl com.parkingless.develop D resetDirectly: mVideoUsage reset!
2025-03-04 18:29:41.462 28022-28119 Camera2CameraImpl com.parkingless.develop D {Camera@7daa75[id=0]} Closing camera.
2025-03-04 18:29:41.462 28022-28119 Camera2CameraImpl com.parkingless.develop D {Camera@7daa75[id=0]} Transitioning camera internal state: OPENED --> CLOSING
2025-03-04 18:29:41.464 28022-28119 CameraStateRegistry com.parkingless.develop D Recalculating open cameras:
Camera State
-------------------------------------------------------------------
Camera@7daa75[id=0] CLOSING
Camera@9ea644[id=1] UNKNOWN
-------------------------------------------------------------------
Open count: 1 (Max allowed: 1)
2025-03-04 18:29:41.464 28022-28119 CameraStateMachine com.parkingless.develop D New public camera state CameraState{type=CLOSING, error=null} from CLOSING and null
2025-03-04 18:29:41.464 28022-28119 CameraStateMachine com.parkingless.develop D Publishing new public camera state CameraState{type=CLOSING, error=null}
2025-03-04 18:29:41.465 28022-28119 Camera2CameraImpl com.parkingless.develop D {Camera@7daa75[id=0]} Resetting Capture Session
2025-03-04 18:29:41.465 28022-28119 Camera2CameraImpl com.parkingless.develop D {Camera@7daa75[id=0]} Skipping Capture Session state check due to current camera state: CLOSING and previous session status: false
2025-03-04 18:29:41.466 28022-28119 Camera2CameraImpl com.parkingless.develop D {Camera@7daa75[id=0]} Releasing session in state CLOSING
2025-03-04 18:29:41.467 28022-28119 SyncCaptureSessionImpl com.parkingless.develop D [androidx.camera.camera2.internal.SynchronizedCaptureSessionImpl@bf33993] Session call super.close()
2025-03-04 18:29:41.468 28022-28119 UseCaseAttachState com.parkingless.develop D Active and attached use case: [] for camera: 0
2025-03-04 18:29:41.469 28022-28119 CaptureSession com.parkingless.develop D onSessionFinished()
2025-03-04 18:29:41.469 28022-28119 Camera2CameraImpl com.parkingless.develop D {Camera@7daa75[id=0]} closing camera
2025-03-04 18:29:41.470 28022-28119 CameraExtImplXiaoMi com.parkingless.develop D releaseCameraDevice: 0
2025-03-04 18:29:41.470 28022-28119 CameraDevice-JV-0 com.parkingless.develop D close: E. id = 0
2025-03-04 18:29:41.472 28022-28022 StreamStateObserver com.parkingless.develop D Update Preview stream state to IDLE
2025-03-04 18:29:41.479 28022-28038 CameraDevice-JV-0 com.parkingless.develop W Device error received, code 4, frame number 26, request ID 0, subseq ID 0
2025-03-04 18:29:41.485 28022-28022 CameraSession com.parkingless.develop I Camera Lifecycle changed to CREATED!
2025-03-04 18:29:41.487 28022-28022 CameraView com.parkingless.develop I Updating CameraSession...
2025-03-04 18:29:41.492 28022-28022 CameraView com.parkingless.develop I Updating CameraSession...
2025-03-04 18:29:41.492 28022-28022 CameraView com.parkingless.develop I Updating CameraSession...
2025-03-04 18:29:41.494 28022-28022 CameraSession com.parkingless.develop I configure { ... }: Waiting for lock...
2025-03-04 18:29:41.494 28022-28022 CameraView com.parkingless.develop I A new configure { ... } call arrived, aborting this one...
2025-03-04 18:29:41.495 28022-28022 CameraSession com.parkingless.develop I configure { ... }: Waiting for lock...
2025-03-04 18:29:41.495 28022-28022 CameraSession com.parkingless.develop I configure { ... }: Updating CameraSession Configuration... Difference(deviceChanged=true, outputsChanged=true, sidePropsChanged=true, isActiveChanged=true, orientationChanged=true, locationChanged=true)
2025-03-04 18:29:41.495 28022-28022 CameraSession com.parkingless.develop I Creating new Outputs for Camera #0...
2025-03-04 18:29:41.495 28022-28022 CameraSession com.parkingless.develop I Using FPS Range: null
2025-03-04 18:29:41.495 28022-28022 CameraSession com.parkingless.develop I Creating Preview output...
2025-03-04 18:29:41.496 28022-28022 CameraSession com.parkingless.develop I Creating Photo output...
2025-03-04 18:29:41.496 28022-28022 CameraSession com.parkingless.develop I Successfully created new Outputs for Camera #0!
2025-03-04 18:29:41.496 28022-28022 CameraSession com.parkingless.develop I Binding Camera #0...
2025-03-04 18:29:41.497 28022-28022 CameraSession com.parkingless.develop I Binding 2 use-cases...
2025-03-04 18:29:41.499 28022-28183 BufferQueueProducer com.parkingless.develop E [SurfaceView[com.parkingless.develop/com.parkingless.MainActivity]#22(BLAST Consumer)22](id:6d7600000023,api:4,p:1586,c:28022) cancelBuffer: BufferQueue has been abandoned
2025-03-04 18:29:41.500 28022-28183 BufferQueueProducer com.parkingless.develop E [SurfaceView[com.parkingless.develop/com.parkingless.MainActivity]#22(BLAST Consumer)22](id:6d7600000023,api:4,p:1586,c:28022) cancelBuffer: BufferQueue has been abandoned
2025-03-04 18:29:41.502 28022-28022 DynamicRangeResolver com.parkingless.develop D Resolved dynamic range for use case androidx.camera.core.Preview-fc97b3e3-c001-4ac9-a302-a2f8bdf4c949 to no compatible HDR dynamic ranges.
DynamicRange@e478393{encoding=UNSPECIFIED, bitDepth=0}
->
DynamicRange@3b18082{encoding=SDR, bitDepth=8}
2025-03-04 18:29:41.502 28022-28022 CameraQuirks com.parkingless.develop D camera2 CameraQuirks =
2025-03-04 18:29:41.502 28022-28022 CameraQuirks com.parkingless.develop D camera2 CameraQuirks =
2025-03-04 18:29:41.503 28022-28022 DeferrableSurface com.parkingless.develop D Surface created[total_surfaces=3, used_surfaces=2](androidx.camera.core.processing.SurfaceEdge$SettableSurface@189f8bf}
2025-03-04 18:29:41.504 28022-28022 DeferrableSurface com.parkingless.develop D Surface created[total_surfaces=4, used_surfaces=2](androidx.camera.core.SurfaceRequest$2@96f61db}
2025-03-04 18:29:41.506 28022-28183 BufferQueueProducer com.parkingless.develop E [SurfaceView[com.parkingless.develop/com.parkingless.MainActivity]#22(BLAST Consumer)22](id:6d7600000023,api:4,p:1586,c:28022) cancelBuffer: BufferQueue has been abandoned
2025-03-04 18:29:41.506 28022-28022 DeferrableSurface com.parkingless.develop D New surface in use[total_surfaces=4, used_surfaces=3](androidx.camera.core.SurfaceRequest$2@96f61db}
2025-03-04 18:29:41.506 28022-28022 DeferrableSurface com.parkingless.develop D use count+1, useCount=1 androidx.camera.core.SurfaceRequest$2@96f61db
2025-03-04 18:29:41.508 28022-28183 BufferQueueProducer com.parkingless.develop E [SurfaceView[com.parkingless.develop/com.parkingless.MainActivity]#22(BLAST Consumer)22](id:6d7600000023,api:4,p:1586,c:28022) cancelBuffer: BufferQueue has been abandoned
2025-03-04 18:29:41.511 28022-28111 ReactNativeJS com.parkingless.develop E { [unknown/unknown: Camera is closed.]
name: 'unknown/unknown',
_code: 'unknown/unknown',
_message: 'Camera is closed.',
_cause: undefined }
Thank you for providing the detailed description and logs. It looks like you're experiencing an issue when taking photos, and I see you have checked the troubleshooting guide. However, the fact that you cannot reproduce this in the example app indicates that the issue might be specific to your implementation or environment.
Please double-check if all permissions are properly granted and if any overlapping components in your application could interfere with the camera operations. If the issue persists, consider simplifying your code to isolate the problem.
If you continue experiencing this issue, please ensure that any relevant logs are gathered using adb logcat while reproducing the issue, as they will help mrousavy understand the problem better.
Don't forget, if you find our work helpful, please consider supporting the project by becoming a sponsor!
Let us know how it goes!
Note: If you think I made a mistake, please ping @mrousavy to take a look.
What's happening?
I want to take a picture, show it and if something is not detected restore the camera.
Reproduceable Code
Relevant log output
Camera Device
Device
Redmi note 9 pro
VisionCamera Version
4.6.3
Can you reproduce this issue in the VisionCamera Example app?
No, I cannot reproduce the issue in the Example app
Additional information
The text was updated successfully, but these errors were encountered: