如何使用 ngx-scanner-qrcode 角度库更改默认摄像头

问题描述 投票:0回答:1

我在项目中使用 ngx-sanner-qrcode 库来扫描 QRCode,但我想知道如何将其默认摄像头从前置摄像头更改为后置摄像头,以获得更好的用户体验。

我原本希望更改配置中的默认摄像头,如下所示:

<ngx-scanner-qrcode #action="scanner" [config]="{deviceActive: 1}"> </ngx-scanner-qrcode>

不幸的是,尚不清楚什么配置设置可以让我实现这一目标。

angular qr-code
1个回答
0
投票

要设置相机,请使用 playDevice(deviceId) 方法,其中 deviceId 可以从

获取
@ViewChild(NgxScannerQrcodeComponent)
scanner?: NgxScannerQrcodeComponent;

const devices =  this.scanner.devices.value; // or subscribe

const deviceId = devices.filter(x => x.label.toLocaleLowerCase().includes('back'))?.[0]?.deviceId ?? devices [0].deviceId; // label back or front for Android devices

this.scanner?.playDevice(deviceId);
© www.soinside.com 2019 - 2024. All rights reserved.