0

I've been scouring the web and S/O for answers as to why the following code does not work, but so far no dice. It is supposed to simply stream the user's video and audio. I am viewing it in Chrome.

<html>
<body>
  <video width="400" height="400" id="userVideo"></video>
<script>
var userStream;
if(navigator.mediaDevices.getUserMedia) {
                //both video and audio
                  navigator.mediaDevices.getUserMedia({
                    video: true,
                    audio: true,
                  }, function(stream) {
                      console.log("got the stream");
                      userStream = stream;

                      document.getElementById("userVideo").srcObject = userStream;

                  });
              }
</script>
</body>
</html>

shman613
  • 196
  • 1
  • 12

3 Answers3

1

Ok, so the issue -- figured out with some fiddling from the example here (https://webrtc.github.io/samples/src/content/getusermedia/gum/) -- is that I had to put an autoplay attribute in the html video tag.

shman613
  • 196
  • 1
  • 12
1

try adding autoplay="true" in the video tag

tonyxforce
  • 13
  • 1
  • 4
0

give this a go:

var userStream;
if(navigator.mediaDevices.getUserMedia) {
   navigator.mediaDevices.getUserMedia({audio: true, video:true}).then(function(stream) {
          console.log("got the stream");
                      userStream = stream;

                 document.getElementById("userVideo").srcObject = userStream;

          });
              }

this one runs for me in Chrome

Doug Sillars
  • 1,625
  • 5
  • 7
  • Nope. Also doesn't work for me, even though I know it's not an issue with either my computer or WebRTC implementation, because https://webrtc.github.io/samples/src/content/getusermedia/gum/ works. – shman613 Apr 19 '20 at 18:56