Capture Video and Audio in Single Browser via WebRTC Media API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Capture Video and Audio</title> | |
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script> | |
</head> | |
<body> | |
<video autoplay></video> | |
<p>Working</p> | |
<script> | |
navigator.mediaDevices | |
.getUserMedia({ | |
audio: true, | |
video: true | |
}) | |
.then((stream) => { | |
document.querySelector("p").textContent = "Connected"; | |
console.log("connected audio"); | |
let video = document.querySelector("video"); | |
video.srcObject = stream; | |
video.play(); | |
}) | |
.catch((e) => { | |
alert(e); | |
document.querySelector("p").textContent = "Not Connected"; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment