简体   繁体   English

我在 Macbook Pro 上只有 Firefox 出现 OverconstrainedError

[英]I got OverconstrainedError only Firefox on Macbook Pro

here is my code这是我的代码

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;
})();

It is working fine on Chrome and Safari BUT in Firefox I got an error OverconstrainedError它在 Chrome 和 Safari 上运行良好,但在 Firefox 中出现错误OverconstrainedError

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

So I try to change width and height constraints to所以我尝试将widthheight约束更改为

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

IT'S WORKING FINE!!!!它工作正常!!!!

Ps.附言。 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. 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.

I want to know why.我想知道为什么。 Please explain to me.请给我解释一下。

This is bug 1286945 .这是错误 1286945 Firefox doesn't yet support downscaling of camera resolutions to constraints. Firefox 还不支持将相机分辨率缩小到约束。

This means Firefox offers native camera modes only at the moment.这意味着 Firefox 目前仅提供原生相机模式。

Workaround解决方法

Remove the max constraint on width and height.删除对宽度和高度的max约束。 min and max are strictly enforced and are causing the OverconstrainedError here. minmax被严格执行,并在此处导致OverconstrainedError

They're also largely unnecessary since the ideal value has gravity.它们在很大程度上也是不必要的,因为ideal值具有重力。 So don't use them unless you're prepared to handle errors and try again with a fallback.所以不要使用它们,除非您准备好处理错误并使用后备重试。

The browser should already find you the resolution closest to the ideal.浏览器应该已经找到最接近理想的分辨率。

Read more about constraints here . 在此处阅读有关约束的更多信息。

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

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