0

i am trying to get video stream through camera, navigator.getuserMedia is not a function error comes.

in another simple page it works, but not in my specific major project

const video = document.getElementById('video')
function startVideo() {
  navigator.getUserMedia(
    { video: {} },
    stream => video.srcObject = stream,
    err => console.error(err)
  )
}
startVideo()

video tag:

<video id="video" width="100%" height="560" autoplay muted></video>

i expect video stream through camera

error:navigator.getUserMedia is not a function
    at startVideo (script.js:3)
    at script.js:9
  • [Navigator#getUserMedia](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getUserMedia): *"This is a legacy method. Please use the newer `navigator.mediaDevices.getUserMedia()` instead."* – barbsan Sep 03 '19 at 08:51
  • after your recommendation" Cannot read property 'getUserMedia' of undefined". i replaced navigator.getUserMedia() with navigator.mediaDevices.getUserMedia() – Muhammad Usman akram Sep 03 '19 at 08:58
  • You can try [this polyfill](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#Using_the_new_API_in_older_browsers). Where do you run your code? – barbsan Sep 03 '19 at 09:02
  • chrome latest version, windows – Muhammad Usman akram Sep 03 '19 at 10:12
  • Do you serve your site on localhost or over https? See also [this question](https://stackoverflow.com/questions/37315361/chrome-navigator-mediadevices-getusermedia-is-not-a-function) – barbsan Sep 03 '19 at 10:32
  • localhost. over http(simlpy) without loclhost it works well. on localhost it doesnt work – Muhammad Usman akram Sep 03 '19 at 10:39

0 Answers0