php - Zxing Barcode Scanner Php 在手机上选择后置摄像头
问题描述
我想这样做,当我使用手机扫描条形码时,总是询问“选择相机(正面或背面)”。如何选择自动后置摄像头.. 我想在移动设备上始终使用后置摄像头。(很抱歉我的英语不好)
<script type="text/javascript">
window.addEventListener('load', function () {
let selectedDeviceId;
const codeReader = new ZXing.BrowserMultiFormatReader()
console.log('code reader initialized')
codeReader.listVideoInputDevices()
.then((videoInputDevices) => {
const sourceSelect = document.getElementById('sourceSelect')
selectedDeviceId = videoInputDevices[0].deviceId
if (videoInputDevices.length >= 5) { // KAÇ KAMERA OLURSA SEÇİM ÇIKACAK...
videoInputDevices.forEach((element) => {
const sourceOption = document.createElement('option')
sourceOption.text = element.label
sourceOption.value = element.deviceId
sourceSelect.appendChild(sourceOption)
})
sourceSelect.onchange = () => {
selectedDeviceId = sourceSelect.value;
};
const sourceSelectPanel = document.getElementById('sourceSelectPanel')
sourceSelectPanel.style.display = 'block'
}
解决方案
推荐阅读
- python - 如何从 Python 字典中删除区分大小写
- python - pandas 如何处理方括号 [] 以及如何避免这种情况?
- javascript - return 语句将在 nodejs 中的 router.post 中执行什么操作
- python - 遍历多个列表并根据每次迭代分配变量
- spring-boot - 无法加载资源 api vue.js
- vbscript - 从 VB 脚本中查找并重新加载 Edge 浏览器窗口?
- javascript - 通过 get() 方法获取属性与将其分配给 web 组件上 connectedCallback 内的变量?
- css - HTML-CSS 如何将元素绑定到另一个元素的右侧?例如输入按钮(左) - 输入文本或任何其他(右)
- java - 在哪里可以获取 Google Ads API URL 端点以调用 Postman?
- javascript - 如何在 AJAX 调用中遍历纬度/经度对数组