and2long / react-native-uvc-camera

UVC Camera component for Reat Native.
MIT License
2 stars 2 forks source link

[BUG] App crash after receiving the permission to use external camera #5

Open Jeanne-1 opened 7 months ago

Jeanne-1 commented 7 months ago

Hi, I have an issue with the connection with my external camera. Everything works until the permission to access the camera is given. Then the app crash without giving any error message.

I use React Native 0.72.10 and the latest version of this library (0.1.4), on a Xiami Pad 6.

Here is my code :

import { UVCCamera } from "@and2long/react-native-uvc-camera";
import React, { useRef, useState, useCallback, useEffect, useMemo } from 'react';
import { StyleSheet, Text, View, Button, AppStateStatus, AppState, GestureResponderEvent, PermissionsAndroid, Image } from 'react-native';
import {SCREEN_WIDTH, SCREEN_HEIGHT} from '../../constants/camera'

export default function UVCCameraScreen() {
    try {
        const camera = useRef<UVCCamera>(null);
        const [picPath, setPicPath] = React.useState<string>();

        const takePhoto = async () => {
          try {
            const photo = await camera.current!!.takePhoto();
            setPicPath(photo.path);
            console.log('photo', photo);
          } catch (error) {
            console.log('error', error);
          }
        };

        console.log(camera.current)

        return (
          <View style={styles.root}>
             <UVCCamera ref={camera} style={styles.cameraView} /> 
            <View style={styles.controlBar}>
              {/* <Button
                title="Open Camera"
                onPress={() => camera.current?.openCamera()}
              />
              <Button
                title="Close Camera"
                onPress={() => camera.current?.closeCamera()}
              /> */}
              {/* <Button title="Take Photo" onPress={takePhoto} /> */}
            </View>
            {picPath && (
              <Image
                source={{ uri: `file:///${picPath}` }}
                style={styles.pic}
                resizeMode="contain"
              />
            )}
          </View>
        );
    } catch (e) {
        console.error('Encountered error ! ')
        console.log(e)
        return (
            <></>
        )
    }
  };

Do you have any idea what could that be about ? Thanks for your help

pranit-yawalkar commented 7 months ago

@Jeanne-1 Facing the same issue, did you get something on it?

yashjawale commented 5 months ago

Same Issue