javascript - 在 html5-qrcode.min.js 上选择后置摄像头

标签 javascript html qr-code

我使用这个二维码扫描仪: https://github.com/mebjas/html5-qrcode

我用这段代码扫描二维码:

         function onScanSuccess(decodedText, decodedResult) {
  // handle the scanned code as you like, for example:
  document.getElementById('text').value = decodedText;
  console.log(`Code matched = ${decodedText}`, decodedResult);
}

function onScanFailure(error) {
  // handle scan failure, usually better to ignore and keep scanning.
  // for example:
  console.warn(`Code scan error = ${error}`);
}

let html5QrcodeScanner = new Html5QrcodeScanner(
    "reader", { fps: 10, qrbox: 250 }, /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess, onScanFailure);

可以将默认相机设置为后置 smartfone 相机。我想在启动时使用后置摄像头运行扫描仪。 谢谢,一些帮助。

最佳答案

我在启动扫描器时使用这段代码完成了它:

facingMode: { exact: "environment"}

也许这会帮助您指明正确的方向。以下是我启动扫描仪时使用设置的方式:

    /** load scanner using back camera **/
    html5QrCode.start({ facingMode: { exact: "environment"} }, config, qrCodeSuccessCallback);

关于javascript - 在 html5-qrcode.min.js 上选择后置摄像头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68812749/

相关文章:

javascript - 在 QR 码符号中存储 vCard 数据的最有效方法

javascript - 从代码库中删除 TypeScript 类型注释和断言

javascript - 如何在 Protractor 测试中设置浏览器大小

javascript - 在 ReduxReducer 中还是在组件的 ShouldComponentUpdate 中进行深度比较?

javascript - jquery 使用 attr() 获取 href 不起作用

php - 如何将生成的 QR 码作为 PNG 存储到 Laravel 中的数据库中

java - 使用数字签名来保护二维码

javascript - 将值从子窗口传递到父窗口

php - CSS 背景图片未加载,似乎找不到图片

javascript - 我想添加独立于 HTML 的 jQuery 文件