Closed gsagergithub closed 8 months ago
+1 Getting the same error. version 3.6.14
+1
I got this error too. If you're getting the error but can use the camera, you can use onError to prevent the error from appearing in the app.
onError={handleCameraError}
<Camera lowLightBoost enableZoomGesture zoom={2} style={StyleSheet.absoluteFill} device={device} isActive={isActive} codeScanner={codeScanner} focusable torch={torchIsOpen ? 'on' : 'off'} onError={handleCameraError} />
const handleCameraError = (e: any) => { console.log('error', e); };
I got this error too. If you're getting the error but can use the camera, you can use onError to prevent the error from appearing in the app.
onError={handleCameraError}
<Camera lowLightBoost enableZoomGesture zoom={2} style={StyleSheet.absoluteFill} device={device} isActive={isActive} codeScanner={codeScanner} focusable torch={torchIsOpen ? 'on' : 'off'} onError={handleCameraError} />
const handleCameraError = (e: any) => { console.log('error', e); };
I can't use the camera at all. It shows as a black screen.
+1
But when I use codeScanner this error doesn't appear.
+1
+1
Change your conditional rendering logic like this:
{ device && <Camera style={styles.container} device={device} isActive={isActive} codeScanner={codeScanner} enableZoomGesture={true} /> }
Change your conditional rendering logic like this:
{ device && <Camera style={styles.container} device={device} isActive={isActive} codeScanner={codeScanner} enableZoomGesture={true} /> }
It doesn't work anyway..
Facing the same issue.
For me its super unstable and causes crashes everytime i either switch the camera Or navigate to and from another page using the navigation library. And sometimes when i show a overlay on top of the view.
It caused me a day of debugging, and it's still happening. I'm on min sdk 26. I use react native without expo bloat
Btw changing
from if(device == null) return ;
to if(!device) return;
helped alot but still not enough
Apparently device can be undefined(i think). Which is contradictory to the docs.
Thanks IHateRNToDontWorry :)
I'm going through the same problem. Android 12 and below: presents the same error Android 13 and above: works normally
However, 25% of my app's user base are on Android version 12, making the use of the library unfeasible.
+1 getting the same error code and video is attached on first render the camera shows up correctly but when navigate back and forth its black screen
i noticed one thing when i change the navigator from bottom tab, the camera then works just fine
import React, { ReactNode, useEffect } from 'react';
import { Image, Linking, StyleSheet, View } from 'react-native';
import {
Camera,
useCameraDevice,
useCameraPermission,
useCodeScanner,
} from 'react-native-vision-camera';
import { Colors } from '../theme';
import { AppText, Button } from './theme';
type Props = {
isActive: boolean;
onScan: (codes: string) => void;
children?: ReactNode | JSX.Element;
};
const QRCodeScanner = ({ isActive, onScan, children }: Props) => {
const { hasPermission, requestPermission } = useCameraPermission();
const device = useCameraDevice('back');
const codeScanner = useCodeScanner({
codeTypes: ['qr', 'ean-13'],
onCodeScanned: (codes) => {
console.log(`Scanned ${codes.length} codes!`);
if (codes?.length > 0) {
if (codes[0].value) {
console.log('Scanned code', codes[0].value);
onScan(codes[0].value);
}
}
},
});
const getPermission = async () => {
if (!hasPermission) {
const res = await requestPermission();
if (!res) {
Linking.openSettings();
}
}
};
useEffect(() => {
getPermission();
}, [hasPermission]);
if (!hasPermission || !device)
return (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: Colors.background,
margin: 32,
gap: 24,
}}
>
<AppText>Shido needs access to Camera</AppText>
<Button
title={'Open Settings'}
onPress={() => Linking.openSettings()}
/>
</View>
);
return (
<View style={styles.container}>
<Camera
key={device.id}
isActive={isActive}
device={device}
codeScanner={codeScanner}
style={StyleSheet.absoluteFill}
/>
<Image
style={styles.image}
source={require('../assets/images/Frame.png')}
/>
{children}
</View>
);
};
export default QRCodeScanner;
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 24,
alignItems: 'center',
justifyContent: 'center',
},
closeButton: {
position: 'absolute',
top: 24,
left: 24,
},
image: {
width: 240,
height: 240,
alignSelf: 'center',
alignItems: 'center',
justifyContent: 'center',
},
});
+1 getting the same error code and video is attached on first render the camera shows up correctly but when navigate back and forth its black screen
i noticed one thing when i change the navigator from bottom tab, the camera then works just fine
import React, { ReactNode, useEffect } from 'react'; import { Image, Linking, StyleSheet, View } from 'react-native'; import { Camera, useCameraDevice, useCameraPermission, useCodeScanner, } from 'react-native-vision-camera'; import { Colors } from '../theme'; import { AppText, Button } from './theme'; type Props = { isActive: boolean; onScan: (codes: string) => void; children?: ReactNode | JSX.Element; }; const QRCodeScanner = ({ isActive, onScan, children }: Props) => { const { hasPermission, requestPermission } = useCameraPermission(); const device = useCameraDevice('back'); const codeScanner = useCodeScanner({ codeTypes: ['qr', 'ean-13'], onCodeScanned: (codes) => { console.log(`Scanned ${codes.length} codes!`); if (codes?.length > 0) { if (codes[0].value) { console.log('Scanned code', codes[0].value); onScan(codes[0].value); } } }, }); const getPermission = async () => { if (!hasPermission) { const res = await requestPermission(); if (!res) { Linking.openSettings(); } } }; useEffect(() => { getPermission(); }, [hasPermission]); if (!hasPermission || !device) return ( <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: Colors.background, margin: 32, gap: 24, }} > <AppText>Shido needs access to Camera</AppText> <Button title={'Open Settings'} onPress={() => Linking.openSettings()} /> </View> ); return ( <View style={styles.container}> <Camera key={device.id} isActive={isActive} device={device} codeScanner={codeScanner} style={StyleSheet.absoluteFill} /> <Image style={styles.image} source={require('../assets/images/Frame.png')} /> {children} </View> ); }; export default QRCodeScanner; const styles = StyleSheet.create({ container: { flex: 1, padding: 24, alignItems: 'center', justifyContent: 'center', }, closeButton: { position: 'absolute', top: 24, left: 24, }, image: { width: 240, height: 240, alignSelf: 'center', alignItems: 'center', justifyContent: 'center', }, });
WhatsApp.Video.2023-12-20.at.2.10.52.PM.mp4
https://github.com/mrousavy/react-native-vision-camera/issues/2291#issuecomment-1862274019 this solution worked for me for now
Same problem when my camera app on from Instagram or other apk i cannot open camera in my app always disconect but when other apk camera close i Can open the camera in my apk
I managed to solve this bug by activating the video
option. It's not a bug-fix, but it worked for me. Try doing the same as me and see if it works for you too.
function App() {
const device = useCameraDevice('back')
if (!device) return null
return (
<Camera
style={StyleSheet.absoluteFill}
device={device}
isActive={true}
photo={true}
video={true}
/>
)
}
I think this has been fixed in the latest version (here on main)
Please try the example app and let me know if the problem is gone!
I'm still facing the same issue. I opened the example app and repeated flipping the direction. My device is a Galaxy S10, Android 12.
logs: https://gist.github.com/bglgwyng/cfe64520b4fbd56a5c74fb153e892f4d
Is this fixed in 3.9.x @bglgwyng ?
Is this fixed in 3.9.x @bglgwyng ?
Nope, we're still experiencing this issue. Version 3.9.0
I'm facing the same issue on Android 12 when navigating between screens
version: 3.9.0
Same here
same here!
Samsung S20FE / Android 13. Same error running the example app.
The same in 3.9.2 but only crash on navigate to the other screen from the screen with camera.
ERROR Camera.onError(session/camera-has-been-disconnected): [session/camera-has-been-disconnected] The given Camera device (id: 0) has been disconnected! Error: CAMERA_IS_DISABLED_BY_ANDROID [session/camera-has-been-disconnected: [session/camera-has-been-disconnected] The given Camera device (id: 0) has been disconnected! Error: CAMERA_IS_DISABLED_BY_ANDROID]
Any android emulator and physical device Samsung S23 - Android 14
Temporary fix - disable camera and then navigate with timeout 200-300 ms
I'm getting this issue at 3.7.0 version, It's closed but I didn't get the resolution. Should I upgrade to which version?
Okk
What's happening?
Hi everyone. I find myself surrounded by the darkest darkness trying to use the rear camera of my Motorola Moto g6 plus, since I'm getting multiple errors. When I navigate to the screen containing the Camera component this one shows up:
Camera.onError(session/camera-has-been-disconnected): [session/camera-has-been-disconnected] The given Camera device (id: 0) has been disconnected! Error: UNKNOWN_CAMERA_DEVICE_ERROR [session/camera-has-been-disconnected: [session/camera-has-been-disconnected] The given Camera device (id: 0) has been disconnected! Error: UNKNOWN_CAMERA_DEVICE_ERROR]
And then, navigating back and forth again I'm getting these other twoCamera.onError(unknown/unknown): [unknown/unknown] CameraDevice was already closed [unknown/unknown: [unknown/unknown] CameraDevice was already closed]
Camera.onError(session/camera-not-ready): [session/camera-not-ready] The Camera is not ready yet! Wait for the onInitialized() callback! [session/camera-not-ready: [session/camera-not-ready] The Camera is not ready yet! Wait for the onInitialized() callback!]
I don't want to leave without telling you that I've tested the native camera application of the phone and it's working properly, and that I have at least three other devices where the application that integrates react native vision camera, runs well. One of them is a Motorola Moto e6 Plus.
I would appreciate any kind of help/guidance to solve this issue. Thank you!
Reproduceable Code
Relevant log output
Camera Device
Device
Motorola Moto g6 Plus
VisionCamera Version
3.6.13
Can you reproduce this issue in the VisionCamera Example app?
I didn't try (⚠️ your issue might get ignored & closed if you don't try this)
Additional information