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> 

3 Answers 3

4

try adding autoplay="true" in the video tag

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

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

1 Comment

Nope. Also doesn't work for me, even though I know it's not an issue with either my computer or WebRTC implementation, because webrtc.github.io/samples/src/content/getusermedia/gum works.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.