react-native-camera icon indicating copy to clipboard operation
react-native-camera copied to clipboard

Expected camera component error when pausePreview is called before takePictureAsync on android

Open mshibl opened this issue 8 years ago • 9 comments

Which implementation are you using

RNCamera - android (works on iOS)

Steps to reproduce

  1. Call camera.pausePreview()
  2. Call camera.takePictureAsync()
  3. 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

mshibl avatar Aug 22 '18 20:08 mshibl

Same scenario, same error - Android 8, react-native-camera 1.2.0

staafl avatar Sep 03 '18 06:09 staafl

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.

swingywc avatar Oct 30 '18 02:10 swingywc

happen to me also, does anyone found a fix ?

niv-breez avatar May 12 '19 03:05 niv-breez

happened to me.. Any fix?

winadiw avatar Jun 10 '19 04:06 winadiw

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.

stale[bot] avatar Aug 09 '19 05:08 stale[bot]

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.

stale[bot] avatar Aug 16 '19 06:08 stale[bot]

Can confirm this is still happening on v3.3.0 When I call .takePictureAsync without .pausePreview first it works.

FilippoArgenti avatar Sep 04 '19 14:09 FilippoArgenti

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! =(');
    }
  }

Nervado avatar Nov 13 '19 15:11 Nervado

Has this been resolved?

tanercura avatar Jul 10 '20 16:07 tanercura