mynameisx
mynameisx

Reputation: 241

Cannot Detect Available Devices

I'm using a tablet and my code does not get the available camera devices.

this.scanner.camerasFound.subscribe((devices: MediaDeviceInfo[]) => {
      this.hasDevices = true;
      this.availableDevices = devices;
});

this.availableDevices variable has no value after putting that lines of code on ngOnInit

html

<zxing-scanner #scanner start="true" [(device)]="currentDevice"></zxing-scanner>

Upvotes: 0

Views: 811

Answers (2)

DW Developer
DW Developer

Reputation: 13

Resolved my problem using this..

this.availableDevices = devices;
this.hasDevices = Boolean(devices && devices.length);

if (this.availableDevices.length > 0)
 this.currentDevice = this.availableDevices[0];

Upvotes: 0

SGalea
SGalea

Reputation: 722

Seems like from here

<zxing-scanner
    [enable]="scannerEnabled"
    [(device)]="desiredDevice"
    [torch]="torch"
    (torchCompatible)="onTorchCompatible($event)"
    (camerasFound)="camerasFoundHandler($event)"
    (camerasNotFound)="camerasNotFoundHandler($event)"
    (scanSuccess)="scanSuccessHandler($event)"
    (scanError)="scanErrorHandler($event)"
    (scanFailure)="scanFailureHandler($event)"
    (scanComplete)="scanCompleteHandler($event)"
></zxing-scanner>

camerasFound Emits an array of video-devices after view was initialized.

so from here

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

Upvotes: 1

Related Questions