首页 > 解决方案 > 在 getusermedia 错误中承诺“待定”

问题描述

我正在尝试从我的移动浏览器(UC 浏览器)获取相机访问权限,但是当我在控制台中检查它时它会继续加载,它显示 video.readystate 为 0 ,并承诺为待处理我不清楚我在谷歌中发现的错误是如果它待定它不会播放相机,任何人都对此有想法

    navigator.mediaDevices.enumerateDevices()
    .then(devices => {
      var videoDevices = [0,0];
      var videoDeviceIndex = 0;
      devices.forEach(function(device) {
        console.log("--- Index:"+videoDeviceIndex);
        console.log(device.kind + ": " + device.label +
          " id = " + device.deviceId);
          console.log(device.kind);
         console.log(device.kind);
        if (device.kind == "videoinput") { 
            console.log(videoDevices[videoDeviceIndex] +":"+ device.deviceId);
            console.log(videoDevices +"--- val:"+videoDeviceIndex);
          videoDevices[videoDeviceIndex++] =  device.deviceId;  
          console.log(videoDevices +"--- after val:"+videoDeviceIndex);       
        }
      });


      var constraints =  {width: { min: 1024, ideal: 1280, max: 1920 },
      height: { min: 776, ideal: 720, max: 1080 },
      deviceId: { exact: videoDevices[1]  } 
    };
    return navigator.mediaDevices.getUserMedia({ video: constraints });

  }).then(function(stream) {
      video.srcObject = stream;
      video.setAttribute("playsinline", true); // required to tell iOS safari we don't want fullscreen
      video.play();
      requestAnimationFrame(tick);
    });

标签: javascript

解决方案


推荐阅读