pix1289
pix1289

Reputation: 514

How do I select which camera lens to use when using back-camera in ngx-scanner?

I am using zxing-js/ngx-scanner for scanning in my Angular application. In Samsung phones, the scanner scans using the wide angel lens which creates an issue in scanning.

I need to be able to allow users to choose between different lenses available or force the scanner component to use the normal lens in order to scan successfully.

So far I have tried this stackoverflow answer and this github answer. I was trying to see if I can atleast get to choose the lens via JS. So far I haven't found any working solution.

Can someone please help with the same?

Upvotes: 1

Views: 1164

Answers (1)

mbagiella
mbagiella

Reputation: 362

did you tried

 <select title="scanner" (change)="onDeviceSelectChange()" #devices>
        <option value="" [selected]="!currentDevice">No Device Selected</option>
        <option *ngFor="let device of availableDevices" [value]="device.deviceId"
          [selected]="currentDevice && device.deviceId === currentDevice.deviceId">{{device.label}}</option>
    </select>

<zxing-scanner class="scanner"
(camerasFound)="onCamerasFound($event)"
></zxing-scanner>

in you component

onCamerasFound(devices: MediaDeviceInfo[]): void {
    this.availableDevices = devices;
    this.hasDevices = Boolean(devices && devices.length);
  }

Upvotes: 0

Related Questions