EN
React - react-webcam 'MediaTrackConstraintSet': The provided double value is non-finite
1
answers
3
points
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
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