繁体   English   中英

我在 Macbook Pro 上只有 Firefox 出现 OverconstrainedError

[英]I got OverconstrainedError only Firefox on Macbook Pro

这是我的代码

const userVideo = document.getElementById("user-video");

const CONSTRAINTS = {
  audio: {
    autoGainControl: false,
    channelCount: 2,
    echoCancellation: true,
    noiseSuppression: true,
    sampleRate: 48000,
    sampleSize: 16,
  },
  video: {
    facingMode: "user",
    width: { min: 0, ideal: 320, max: 320 },
    height: { min: 0, ideal: 240, max: 240 },
    frameRate: { ideal: 15, max: 30 },
  },
};

(async () => {
  const userMedia = await navigator.mediaDevices.getUserMedia(CONSTRAINTS);
  console.log(userMedia);

  userVideo.srcObject = userMedia;
})();

它在 Chrome 和 Safari 上运行良好,但在 Firefox 中出现错误OverconstrainedError

MediaStreamError
constraint: "width"
message: "Constraints could be not satisfied."​
name: "OverconstrainedError"
stack: ""

所以我尝试将widthheight约束更改为

width: { min: 0, ideal: 320, max: 360 },
height: { min: 0, ideal: 240, max: 300 },

它工作正常!!!!

附言。 I tested WebRTC on this website https://test.webrtc.org/ Firefox on MacBook not support 320x240 but another browser and another OS can support it.

我想知道为什么。 请给我解释一下。

这是错误 1286945 Firefox 还不支持将相机分辨率缩小到约束。

这意味着 Firefox 目前仅提供原生相机模式。

解决方法

删除对宽度和高度的max约束。 minmax被严格执行,并在此处导致OverconstrainedError

它们在很大程度上也是不必要的,因为ideal值具有重力。 所以不要使用它们,除非您准备好处理错误并使用后备重试。

浏览器应该已经找到最接近理想的分辨率。

在此处阅读有关约束的更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM