Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS VIDEO | DOMException: Could not start video source

Tags:

javascript

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

like image 435
Yunus Emre Nalbant Avatar asked Mar 24 '20 19:03

Yunus Emre Nalbant


People also ask

Could not start video source webcam JS?

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.

Could not start video source?

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.


Video Answer


3 Answers

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.

like image 92
Some guy Avatar answered Oct 23 '22 09:10

Some guy


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

like image 1
akgnplc Avatar answered Oct 23 '22 08:10

akgnplc


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)
);
like image 8
Dawid Pura Avatar answered Oct 23 '22 09:10

Dawid Pura