Created
October 31, 2019 19:59
-
-
Save autonome/89d1dd2be732dc5622c358185ff412f3 to your computer and use it in GitHub Desktop.
getUserMedia camera test
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
<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