Languages

React - react-webcam 'MediaTrackConstraintSet': The provided double value is non-finite

3 points
Asked by:
Majid-Hajibaba
972

I am using react-webcam package in my project and I got the following error:

TypeError: Failed to execute 'getUserMedia' on 'MediaDevices': Failed to read the 'video' property from 'UserMediaStreamConstraints': Failed to read the 'aspectRatio' property from 'MediaTrackConstraintSet': The provided double value is non-finite.

Webcam component usage:

<Webcam
  ref={webcamRef}
  className={styles.webcam}
  mirrored={true}
  audio={false}
  videoConstraints={{
      facingMode: 'user',
      aspectRatio: ratio,
  }}
/>

The ratio is calculated using useWindowSize hook.

1 answer
3 points
Answered by:
Majid-Hajibaba
972

The Webcam component may not be receiving the calculated ratio value, you need to debug your application.

You can also use isFinite() method and wrap the Webcam component with conditional rendering to render it once the finite ratio is received:

<div>
  {isFinite(ratio) && (
    <Webcam
      ref={webcamRef}
      className={styles.webcam}
      mirrored={true}
      audio={false}
      videoConstraints={{
          facingMode: 'user',
          aspectRatio: ratio,
      }}
    />
  )}
</div>
0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join