Skip to content

Instantly share code, notes, and snippets.

@matt-mcalister
Last active February 8, 2018 17:14
Show Gist options
  • Save matt-mcalister/da36b8583475e042e87af965c6c3e4c7 to your computer and use it in GitHub Desktop.
Save matt-mcalister/da36b8583475e042e87af965c6c3e4c7 to your computer and use it in GitHub Desktop.
const videoPlayer = document.getElementById("video-player") // this is a <video> element
onSuccessWithSrcObject(stream) {
videoPlayer.srcObject = stream;
}
onSuccessWithSrc(stream) {
videoPlayer.src = window.URL.createObjectURL(stream);
}
navigator.mediaDevices.getUserMedia({ audio: true, video: true })
.then(stream => {
if ("srcObject" in videoPlayer) {
onSuccessWithSrcObject(stream)
} else {
onSuccessWithSrc(stream)
}
})
.catch( err => alert(`Bummer! ${err.name}.`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment