Android Question Camera1_Preview event is sometimes triggered, sometimes not

Discussion in 'Android Questions' started by jo1234, May 5, 2019.

  1. jo1234

    jo1234 Member Licensed User


    I use Erel's beautiful barcode scanning method (camEx, Mobile Vision API) to detect barcodes. The barcode is detected in the Camera1_Preview event, the scanning is stopped, the result is shown and the scanning continues to detect the next barcode.

    To get faster reponses, I do not release the camera after each scan but only stop the preview (camEx.StopPreview).
    After showing the result, I continue with camEx.StartPreview to scan the next barcode. That works in most cases on most devices.
    However, I have instances (e.g. Galaxy Tab with Android 4.2.2, where the preview is started again and shows me the live video, however, the Camera1_Preview event is not triggered.
    If I release the cam and initialize the cam again, the Camera1_Preview event is triggered again.

    Any idea how it could happen that camEx.StartPreview restarts the video stream but not the Preview events?
    As I said, the Preview event works in most cases and is not deactivated in the class module.

  2. Erel

    Erel Administrator Staff Member Licensed User

    Why do you need to stop the preview at all?
  3. jo1234

    jo1234 Member Licensed User

    I have a scan view. When a barcode is detected, the preview is stopped, the scan view is hidden and the result view is shown. Then the user can either immediately continue to scan or do something else. In case he wants to continue to scan I want the camera to be quick and avoid to initialize the camera again because that takes a moment (unless it has to be done).

    My solution at the moment is that after StartPreview I start a timer, which is disabled in the Preview event. In the rare cases that the Preview event does not fire after resuming the preview, the timer will initiate the camera again, which makes the Preview event fire again.

  4. Erel

    Erel Administrator Staff Member Licensed User

    You can do it without stopping the preview. Show an ImageView with the scanned barcode.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice