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

🐛 Error in IOS when implementing flash: {"error": [unknown/unknown: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x281631710 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}}]} #1606

Closed
3 of 4 tasks
tatianavazquez opened this issue May 30, 2023 · 5 comments
Labels
🐛 bug Something isn't working

Comments

@tatianavazquez
Copy link

What were you trying to do?

I'm implementing the flash functionality.

Reproduceable Code

CAMERA MODAL COMPONENT:

const CameraModal = ({visible, setVisible}) => {
  const [headerVisible, setHeaderVisible] = useState(false);

  const closeModal = () => {
    setVisible(false);
    setPhoto('');
  };

  const { t } = useTranslation();

  return (
    <Modal
      visible={visible}
      setVisible={() => setVisible(!visible)}
      transparent={false}
      modalStyle={{
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: theme.colors.black,
        height: '100%',
      }}
    >
      <Spinner
        visible={showUntouchableOverlay}
        textContent={t('chat.loading')}
      />
      {photo ? (
        <PhotoUI
          image={{ uri: Platform.OS === 'ios' ? photo : `file://${photo}` }}
          nativeChatProps={nativeChatProps}
          onClose={closeModal}
        />
      ) : (
        <CameraUI />
      )}
    </Modal>
  );
};

export default CameraModal;


CAMERA UI:

const CameraUI = () => {
 const [photo, setPhoto] = useState('');
  const [cameraPermission, setCameraPermission] =
    useState<CameraPermissionRequestResult>();
  const camera = useRef<Camera>(null);
  const [cameraPosition, setCameraPosition] = useState<'front' | 'back'>(
    'back',
  );
  const isPressingButton = useSharedValue(false);
  const devices = useCameraDevices();
  const cameraDevice = devices[cameraPosition];

  const ReanimatedCamera = Reanimated.createAnimatedComponent(Camera);
  Reanimated.addWhitelistedNativeProps({
    zoom: true,
  });

  const setIsPressingButton = useCallback(
    (_isPressingButton: boolean) => {
      isPressingButton.value = _isPressingButton;
    },
    [isPressingButton],
  );

  const onMediaCaptured = useCallback((media: PhotoFile, type: 'photo') => {
    setPhoto(media.path);
  }, []);

  useEffect(() => {
    (async () => {
      const cameraPermissionStatus = await Camera.requestCameraPermission();
      setCameraPermission(cameraPermissionStatus);
    })();
  }, []);

  const [flash, setFlash] = useState<'off' | 'on'>('off');
  const supportsFlash = cameraDevice?.hasFlash ?? false;

  const onFlashPressed = useCallback(() => {
    setFlash(f => (f === 'off' ? 'on' : 'off'));
  }, []);

  return (
    <Container>
      <CameraHeader
        visible={headerVisible}
        flashOnPress={onFlashPressed}
        flash={supportsFlash ? flash : 'off'}
        arrowOnPress={() => setHeaderVisible(!headerVisible)}
        rawOnPress={() => console.log('TODO: Toggle raw')}
        liveOnPress={() => console.log('TODO: Toggle live')}
      />
        <ReanimatedCamera
          style={{
            width: screenWidth,
            height: screenHeight * 0.75,
          }}
          device={cameraDevice}
          isActive
          ref={camera}
          photo
          enableZoomGesture={false}
          animatedProps={cameraAnimatedProps}
          onError={error => {
            console.log({ error });
          }}
        />
      <Buttons>
        <ButtonsComponents.PhotoGalleryButton
          onPress={() => console.log('TODO: open gallery')}
        />
        <ButtonsComponents.CaptureButton
          camera={camera}
          onMediaCaptured={onMediaCaptured}
          cameraZoom={zoom}
          minZoom={minZoom}
          maxZoom={maxZoom}
          flash={supportsFlash ? flash : 'off'}
          enabled
          setIsPressingButton={setIsPressingButton}
        />
        <ButtonsComponents.ChangeCameraButton
          onPress={() => console.log('TODO: change camera')}
        />
      </Buttons>
    </Container>
  )
};

export default CameraUI;

What happened instead?

Sometimes when I click on the flash icon, the camera turns black and nothing happens until I click on the icon again.
The console.log for 'error' on the Camera, gives me this error:

LOG {"error": [unknown/unknown: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x280d5bdb0 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}}]}

This error logs whenever I click on the camera icon.

Relevant log output

No response

Device

iPhone 13

VisionCamera Version

^2.15.4

Additional information

@tatianavazquez tatianavazquez added the 🐛 bug Something isn't working label May 30, 2023
@tatianavazquez tatianavazquez changed the title 🐛 🐛 Error in IOS when implementing flash: {"error": [unknown/unknown: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x281631710 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}}]} May 30, 2023
@thunderousNinja
Copy link

I am facing the same issue, any updates? I am able to repro if I take two pictures right after each other.

@tatianavazquez
Copy link
Author

No, I don't have any updates and I don't know why this is happening... :/ where can we get help?

@myselfuser1
Copy link

@alessandrom
Copy link

Same

@mrousavy
Copy link
Owner

mrousavy commented Aug 3, 2023

Hey - hmm maybe the device does not support flash?

@mrousavy
Copy link
Owner

Closing as this is a stale issue - this might have been fixed with the full rewrite in VisionCamera V3 (🥳) - if not, please create a new issue.

If your issue has been fixed, consider sponsoring me on GitHub to say thanks 💖

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

No branches or pull requests

5 participants