Created
December 11, 2018 14:35
-
-
Save vmussak/214563df2cf02857d27ae4a1c0f10514 to your computer and use it in GitHub Desktop.
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
iniciarCamera() { | |
let nav = <any>navigator; | |
nav.getUserMedia = nav.getUserMedia || nav.mozGetUserMedia || nav.webkitGetUserMedia; | |
if (!nav.getUserMedia) { | |
UiSnackbar.show({ | |
text: 'Seu navegador não tem suporte para Webcam' | |
}); | |
return; | |
} | |
let options = { | |
video: true, | |
audio: false | |
}; | |
nav.getUserMedia(options, (stream) => { | |
let webcamUrl = URL.createObjectURL(stream); | |
this.videoSrc = this.sanitizer.bypassSecurityTrustUrl(webcamUrl); | |
let video = this.element.nativeElement.querySelector('#video-user'); | |
video.autoplay = true; | |
let reconhecimento = this; | |
let getVideoSize = function() { | |
reconhecimento.videoWidth = video.videoWidth; | |
reconhecimento.videoHeight = video.videoHeight; | |
video.removeEventListener('playing', getVideoSize, false); | |
}; | |
video.addEventListener('playing', getVideoSize, false); | |
}, (err) => { | |
UiSnackbar.show({ | |
text: 'Ocorreu um erro ao iniciar a Webcam' | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment