Skip to content

Instantly share code, notes, and snippets.

@vmussak
Created December 11, 2018 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmussak/214563df2cf02857d27ae4a1c0f10514 to your computer and use it in GitHub Desktop.
Save vmussak/214563df2cf02857d27ae4a1c0f10514 to your computer and use it in GitHub Desktop.
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