mrousavy / react-native-vision-camera

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

🐛 [device/flash-not-available: The Camera Device does not have a flash unit! Make sure you select a device where `device.hasFlash`/`device.hasTorch` is true.] #3144

Open chandanpradhanin opened 3 weeks ago

chandanpradhanin commented 3 weeks ago

What's happening?

The back camera is working for me, but I am experiencing this issue when using the front camera to take selfies. I am using getCameraDevice(devices, 'front') to obtain the front camera. I would appreciate your guidance in fixing this or letting me know if anything is incorrect.

Reproduceable Code

const frontDevice = getCameraDevice(devices, 'front');
 <Camera
              ref={ref => {
                this.camera = ref;
              }}
              style={cameraStyle}
              device={frontDevice}
              isActive={isActive}
              photo={true}
              torch={"off"}
              enableZoomGesture={true}
            />

Relevant log output

error [device/flash-not-available: The Camera Device does not have a flash unit! Make sure you select a device where `device.hasFlash`/`device.hasTorch` is true.]

Camera Device

{
  "formats": [],
  "sensorOrientation": "landscape-right",
  "hardwareLevel": "full",
  "maxZoom": 4,
  "minZoom": 1,
  "maxExposure": 12,
  "supportsLowLightBoost": false,
  "neutralZoom": 1,
  "physicalDevices": [
    "wide-angle-camera"
  ],
  "supportsFocus": true,
  "supportsRawCapture": false,
  "isMultiCam": false,
  "minFocusDistance": 0,
  "minExposure": -24,
  "name": "1 (FRONT) androidx.camera.camera2",
  "hasFlash": false,
  "hasTorch": false,
  "position": "front",
  "id": "1"
}

Device

Xiaomi Redmi Note 8 Pro - M1906G71

VisionCamera Version

4.5.2

Can you reproduce this issue in the VisionCamera Example app?

Yes, I can reproduce the same issue in the Example app here

Additional information

maintenance-hans[bot] commented 3 weeks ago

Guten Tag, Hans here! 🍻

It looks like you are encountering an issue with ze front camera on your Xiaomi Redmi Note 8 Pro. From ze logs, it seems like ze device does not have a flash unit, which is correct; ze hasFlash and hasTorch properties are both false.

If you need ze flash for your selfies, perhaps you might consider using ze back camera instead, as it typically has a flash. If you are looking for assistance beyond this, please provide additional logs from adb logcat or any other debugging information to help mrousavy troubleshoot further!

Otherwise, it might be wise to check out ze Troubleshooting Guide in more detail. Also, if you wish for priority response, consider sponsoring the project here.

Keep up ze good work!

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

chandanpradhanin commented 3 weeks ago

@mrousavy Thank you for your prompt response. As I do not intend to use a flash or torch while using the front camera, why is it still necessary that device.hasFlash and device.hasTorch be true? Also, I have used the torch={"off"} property, so why is this issue still occurring?

mrousavy commented 3 weeks ago

If you don't have a device you shouldn't render the Camera. This is literally what the error message says. Use Typescript, you cannot pass null to device

EDIT: Sorry I didn't read the whole issue - maybe it works when yoh pass torch={undefined}?

chandanpradhanin commented 3 weeks ago

@mrousavy i am not passing null to device prop. I am passing the which is return by getCameraDevice(devices, 'front') and camera view is opened in my app but takePhoto function is not working for me. So i have changed in the options flash: 'off' like below and now its working for me.

const options = { base64: false, flash: 'off', skipMetadata: true };

let response = await this.camera.takePhoto(options);