首页 > 解决方案 > 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'
                  } 
        
                 

标签: phpmobilecamerabarcodezxing

解决方案


推荐阅读