🐛 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)"}}]}
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
- [ ] I am using Expo
- [X] I have read the Troubleshooting Guide
- [X] I agree to follow this project's Code of Conduct
- [X] I searched for similar issues in this repository and found none.
I am facing the same issue, any updates? I am able to repro if I take two pictures right after each other.
No, I don't have any updates and I don't know why this is happening... :/ where can we get help?
Try this https://www.youtube.com/playlist?list=PLQhQEGkwKZUrempLnmxjt7ZCZJu1W3p2i
Same
Hey - hmm maybe the device does not support flash?
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 💖
Hello, @mrousavy Still facing below error.
[unknown/unknown: Error Domain=AVFoundationErrorDomain
Code=-11800 "The operation could not be completed" UserInfo={NSLocali
zedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x300f15590 {Error Domain=NS
OSStatusErrorDomain Code=-12780 "(null)"}}]
I'm using this version.
"react-native-vision-camera": "4.6.3",
Still facing this issue only on iOS physical device while trying to access front camera:
[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=0x3024523d0 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}}]
"react-native-vision-camera": "^4.6.4"
Still facing this issue on iOS physical device both camera:
[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=0x3024523d0 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}}]
"react-native-vision-camera": "^4.6.4" "react-native": "0.75.4",
info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
when call camera.current.startRecording still got that err. Have any update :(
Hello,
The root cause of this issue, as per my observation, is that you might have unmounted the screen which contains the <Camera /> component which causes this error. For example, using navigation methods like navigation.replace() or navigation.resetStack will unmount the screen component and any preceding screen containing the <Camera /> component will throw the mentioned error.
Hello, The root cause of this issue, as per my observation, is that you might have unmounted the screen which contains the
<Camera />component which causes this error. For example, using navigation methods likenavigation.replace()ornavigation.resetStackwill unmount the screen component and any preceding screen containing the<Camera />component will throw the mentioned error.
hmm, it not true with my situation.
<Camera /> is on a modal. it have call in a FormCreate Screen.
And both of them still in stack.
But still got err: Error Domain=AVFoundationErrorDomain Code=-11800. Still record without sound
Hello, The root cause of this issue, as per my observation, is that you might have unmounted the screen which contains the
<Camera />component which causes this error. For example, using navigation methods likenavigation.replace()ornavigation.resetStackwill unmount the screen component and any preceding screen containing the<Camera />component will throw the mentioned error.hmm, it not true with my situation.
<Camera />is on a modal. it have call in a FormCreate Screen. And both of them still in stack. But still got err: Error Domain=AVFoundationErrorDomain Code=-11800. Still record without sound
Perhaps, you can verify if your screen component/modal, containing the <Camera /> component, is being unmounted using useEffect hook like this:
useEffect(() => {
console.log('screen mounted!');
return () => {
console.log('Unmounted!');
}
}, []);
This error can also occur when you audio file is corrupted, empty, Doesn't exists or any unsupported configurations. Example: Unsupported Sample rate, bit depth, To test try to replace with a test audio file..
@ani-backend Which audio file you're talking about ?
i recently updated my react-native project. removed react-native-camera and added react-native-vision-camera i need video with audio but audio={true} throwing error
I'm facing the same problem with version 4.7.1. I believe @mgulfam0722 is right on his observation. I also noticed the same situation. In my case this error happens when rotating the device (as I remount the component). Did you find a solution for this?
@ani-backend Which audio file you're talking about ?
i recently updated my react-native project. removed react-native-camera and added react-native-vision-camera i need video with audio but audio={true} throwing error
Getting exactly same error but this only happen in iOS "react-native-vision-camera": "^4.7.0",
I'm facing the same problem with version
4.7.1. I believe @mgulfam0722 is right on his observation. I also noticed the same situation. In my case this error happens when rotating the device (as I remount the component). Did you find a solution for this?
@williamgurzoni Have you found any solution yet? Let me know.
I'm facing the same problem with version
4.7.1. I believe @mgulfam0722 is right on his observation. I also noticed the same situation. In my case this error happens when rotating the device (as I remount the component). Did you find a solution for this?@williamgurzoni Have you found any solution yet? Let me know.
In my case the error was happening when rotating the device. In fact after many attempts I figured out that the problem was with React re-rendering the camera component, which was causing it to remount. So I fixed my case by refactoring the way the component works and avoiding re-rendering the camera. But I believe that there is still something going on here.