'JS VIDEO | DOMException: Could not start video source

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



Solution 1:[1]

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

Solution 2:[2]

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.

Solution 3:[3]

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!!Error solved!! DOM Exception Could not start video source

Solution 4:[4]

If anyone have such an error and you are working on a laptop. You can try bending your laptop monitor in both directions. Sometimes the cable comes loose. This helped in my case.

Solution 5:[5]

Also look into Feature-Policy HTTP header, both on the website and on the host web server config, and make sure camera access is allowed.

Solution 6:[6]

I have tried all the other solution but nothing is work. Then finally i need to uninstall my camera driver in Device Manager and then scan for hardware changes. Try to run the app again and it's working.

I'm building electron desktop app in windows 10.
electron: 15.3.0

Source video that helped me: https://www.youtube.com/watch?v=XE2ULFlzkxw

Solution 7:[7]

I went to the browser settings for camera and noticed that the default camera was showing as "Leap Motion" which is not a standard camera device. I changed to an actual webcam and the problem was solved.

Solution 8:[8]

Sometimes this type of error also appears when you try to make a peer-to-peer call system and your tests are done on the same device. The camera is already used by the initiator and the receiver can no longer activate the camera.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dawid Pura
Solution 2 Some guy
Solution 3 akgnplc
Solution 4 Fakt309
Solution 5 Jay Singh
Solution 6 Wachid
Solution 7 fmacdee
Solution 8 Madel M6TM