[expo-camera] "Error: Camera not running" after setting pictureSize prop

Please provide the following:

  1. SDK Version: 42.0.0
  2. Platforms(Android/iOS/web/all): Android

I’d like to set ratio and pictureSize after Camera is ready in order to select a good picture size. Setting the ratio works fine, but when altering pictureSize in handleCameraReady, I’ll always get an error “Camera is not running” when trying to call camera functions. Is there anything I’m doing wrong?

Thanks for your help,
Florian

Excerpt from my code:

  const PREFERRED_RATIOS = ['16:9', '4:3']

  const cameraRef = useRef()

  // initial values
  const [selectedRatio, setSelectedRatio] = useState('4:3')
  const [selectedPictureSize, setSelectedPictureSize] = useState('640x480')

  const handleCameraReady = async () => {
    if (Platform.OS === 'android') {
      const supportedRatios = await cameraRef.current?.getSupportedRatiosAsync()
      const selectedRatio = PREFERRED_RATIOS.find(pr => supportedRatios.includes(pr)) ?? supportedRatios[0]
      const availablePictureSizes = await cameraRef.current?.getAvailablePictureSizesAsync(selectedRatio)
      setSelectedRatio(selectedRatio)
      setSelectedPictureSize(availablePictureSizes[availablePictureSizes.length - 1])
    }
    setIsCameraReady(true)
  }

  <Camera
    onCameraReady={handleCameraReady}
    pictureSize={selectedPictureSize}
    ratio={selectedRatio}
    ref={cameraRef}
    style={styles.camera}
    type={Camera.Constants.Type.back}
    useCamera2Api
  >
    // ...
  </Camera>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.