I want to get a video from the webcam using JS but no footage.
MESSAGE:
DOMException: Could not start video source
App.js
const video = document.getElementById("video");
function startVideo() {
navigator.getUserMedia(
{
video: {}
},
stream => (video.srcObject = stream),
err => console.log(err)
);
}
startVideo();
index.html
...
<body>
<video id="video" width="720" height="540" autoplay muted></video>
</body>
...
thanks for your help
This error message is mostly because of your camera is being used by some other application in your system. If you are trying to access the camera only from one browser, then check if the camera is used by other application and close it.
If you are receiving the message “The webcam is in use by another application” or “NotReadableError: Could not start video source” check that your webcam is not in use by another application such as Skype or Facebook video chat. First, if you have ManyCam installed, first upgrade it to the latest version.
If anyone else is having this problem and nothing else helps. Make sure that your camera is not already claimed/used by a different software/browser.
In Windows 10 go to settings->privacy->App permission(left side)->Microphone-> enable 'Allow apps to access your microphone' After that retry with your JS program....It will work!!
TLDR: I have tested your code and had to change it a bit:
https://codepen.io/puradawid/pen/PoqxzPQ
It looks like the problem lays here:
navigator.getUserMedia({
video: {}
},
stream => { video.srcObject = stream },
err => console.log(err)
);
Regarding to docs navigator.getUserMedia
is deprecated and there is navigator.mediaDevices.getUserMedia
that supports it. However, changing that up doesn't solve the correct problem which is your callback functions. This method returns Promise
that is controlled by .then()
, so changing it allows me to see my face in codepen:
navigator.mediaDevices.getUserMedia({
video: true
}).then(
stream => (video.srcObject = stream),
err => console.log(err)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With