Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BarcodeScanner stops detect after some time #243

Open
MateusMiotto opened this issue Jun 18, 2024 · 3 comments
Open

BarcodeScanner stops detect after some time #243

MateusMiotto opened this issue Jun 18, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@MateusMiotto
Copy link

MateusMiotto commented Jun 18, 2024

Describe the bug
After an indeterminate amount of time, Barcode detection simply does not happen. I didn't get anything different in the log, just the usual:
[UseCaseAttachState] Active and attached use case: [androidx.camera.core.Preview-d8c6eaeb-2536-4024-99fa-912bef01aeb1128811641, androidx.camera.core.ImageAnalysis-a1ea55de-92b1-473a-95d1-b0a97f9ffe90219505695] for camera: 1
[CaptureSession] Attempting to submit CaptureRequest after setting
[CaptureSession] Issuing request for session.

In my tests, after approximately 1~2 hours the detection simply stopped.

To Reproduce
I uploaded a project based on the library example, with MVVM sample (even in code behind the bug persists)

Steps to reproduce the behavior:

  1. Clone and restore packages of https://github.com/MateusMiotto/BarcodeScanner
  2. Run the project
  3. Wait a certain amount of time without making the detection, (for me 1~2 hours without taking any reading) and the detection simply stops happening and without any error in logs

Expected behavior
The component, even with the camera open performing the detection, even without detecting any barcode for hours, does not stop scanning

Smartphone (please complete the following information):

  • Device: [Note 8 pro, Samsumg A54, Galaxy Tab A9+]
  • OS: [Android 14 and Android 11]
  • Version [Maui v8.0.40]
@ManuLin
Copy link

ManuLin commented Jul 3, 2024

I am facing the same issue Mateus mentioned. After a random amount of time, the scanner seems to stop scanning without an exception being thrown. Any hints are highly appreciated. We are using the "BarcodeScanner.Mobile.Maui" package in version 8.0 and can observe the issue on Android devices as well.

@MateusMiotto
Copy link
Author

Any updates about this issue?

@DannyGit
Copy link

DannyGit commented Nov 7, 2024

Hi,
we had the same issue in our NET8 Maui app and solved it by adding a Timer to the code-behind that toggles the 'IsScanning' Property of the CameraView, effectively re-starting the scan process every few seconds

protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
       ..        
      StartScanning();
}

  /// <summary>
  /// The scan process will be active for four seconds and then get reset by a timer.
  /// The timer will disable the scan process for a short period and then re-enable it for another four seconds and so on.
  /// workaround for: https://github.com/JimmyPun610/BarcodeScanner.Mobile/issues/243
  /// </summary>
  private void StartScanning()
  {
      this._viewModel.IsScanning = true;
      
      // Create a timer and set a two second interval.
      scannerTimer = new System.Timers.Timer();
      scannerTimer.Interval = 4000;

      // Hook up the Elapsed event for the timer. 
      scannerTimer.Elapsed += ToggleIsScanning;

      // Have the timer fire repeated events (true is the default)
      scannerTimer.AutoReset = true;

      // Start the timer
      scannerTimer.Enabled = true;
  }

  // disable scanner and after short delay, re-enable scanning again to re-init scan process
  private async void ToggleIsScanning(object sender, ElapsedEventArgs e)
  {
      this._viewModel.IsScanning = false;
      await Task.Delay(250);
      this._viewModel.IsScanning = true;
  }

  protected override void OnNavigatedFrom(NavigatedFromEventArgs args)
  {
      ...        
      scannerTimer.Enabled = false;
      scannerTimer.Elapsed -= ToggleIsScanning;
      scannerTimer.Dispose();
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants