Expected camera component error when pausePreview is called before takePictureAsync on android
Which implementation are you using
RNCamera - android (works on iOS)
Steps to reproduce
- Call camera.pausePreview()
- Call camera.takePictureAsync()
- catch and log error:
Expected camera component
takePicture = async () => {
try {
if (this.camera) {
this.camera.pausePreview();
const data = await this.camera.takePictureAsync();
// ... use picture data
}
} catch (err) {
console.error(err);
}
};
Expected behaviour
The camera should pause the preview, and then take the picture
Actual behaviour
Throws an error: Error: takePictureAsync: Expected a Camera component
Environment
- React Native version: 0.55.4
- React Native platform + platform version: Android 6.0
react-native-camera
Version: 1.2.0
Same scenario, same error - Android 8, react-native-camera 1.2.0
Having same problem. In my project, I want to confirm the preview is the same as the one captured, therefore calling this.camera.pausePreview() before await this.camera.takePictureAsync().
Is this the normal way to use this camera package? There is no clear guide to teach how to use this camera.
happen to me also, does anyone found a fix ?
happened to me.. Any fix?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and i will leave this open.
Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.
Can confirm this is still happening on v3.3.0 When I call .takePictureAsync without .pausePreview first it works.
Same here:
RNCamera: 3.9.0 RN: 0.61.4
Plattaform: Android
async function takePicture() {
try {
if (camera) {
// Pause the camera preview
// Update the state to indicate loading
setLoading(true);
// Set the options for the camera
const options = {
base64: true,
};
// Get the base64 version of the image
camera.pausePreview();
const data = await camera.takePictureAsync(options);
// Call the identify function
identifyImage(data.base64);
}
} catch (error) {
Alert.alert('Something whent wrong! =(');
}
}
Has this been resolved?