Skip to content

Instantly share code, notes, and snippets.

@autonome
Created October 31, 2019 19:59
Show Gist options
  • Save autonome/89d1dd2be732dc5622c358185ff412f3 to your computer and use it in GitHub Desktop.
Save autonome/89d1dd2be732dc5622c358185ff412f3 to your computer and use it in GitHub Desktop.
getUserMedia camera test
<style>
html, body, div, a-scene {
background-color: transparent;
}
#video {
/* overrule a-frame default styles */
width: 100% !important;
max-width: 100% !important;
height: auto !important;
position: absolute;
top: 0;
left: 0;
}
</style>
<video id="video" autoplay loop muted></video>
<script>
document.addEventListener('DOMContentLoaded', () => {
let videoElement = document.querySelector('#video');
navigator.mediaDevices.getUserMedia({video: true}).then(function(stream) {
videoElement.srcObject = stream;
// never fires on Firefox
videoElement.onloadedmetadata = function(e) {
alert('onloadedmetadata');
videoElement.play();
};
videoElement.play();
}, function(err) {
console.error(err);
});
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment