无法使用JavaScript在小米和三星的移动设备上关闭手电筒

时间:2018-06-27 05:56:41

标签: javascript android mobile

WebRTC API允许您从Chrome打开手机上的手电筒功能。但是,您无法将其关闭。我已经在小米手机和三星设备上看到了这个问题。

function toggleFlash() {
  let that = this;
  const mediaStreamTrack = this.$refs.video.srcObject.getVideoTracks()[0];
  const imageCapture = new window.ImageCapture(mediaStreamTrack);
  imageCapture.getPhotoCapabilities().then(() => {
    if (that.tourch === false) {
      that.tourch = true;
      mediaStreamTrack.applyConstraints({
        advanced: [{ torch: true }]
      });
    } else if (that.tourch === true) {
      that.tourch = false;
      mediaStreamTrack.applyConstraints({
        advanced: [{ torch: false }]
      });
    }
  });
}

0 个答案:

没有答案