Last active
April 8, 2023 09:38
-
-
Save ardianta/da3bd8665ad2110eb9c4cc07af9dfe70 to your computer and use it in GitHub Desktop.
kode untuk menampilkan webcam dalam HTML
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
<div class=""> | |
<video autoplay="true" id="video-webcam"> | |
Izinkan untuk Mengakses Webcam untuk Demo | |
</video> | |
<button onclick="takeSnapshot()">Ambil Gambar</button> | |
</div> | |
<script> | |
var video = document.querySelector("#video-webcam"); | |
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia; | |
if (navigator.getUserMedia) { | |
navigator.getUserMedia({ video: true }, handleVideo, videoError); | |
} | |
function handleVideo(stream) { | |
video.src = window.URL.createObjectURL(stream); | |
console.log(stream); | |
} | |
function videoError(e) { | |
// do something | |
alert("Izinkan menggunakan webcam untuk demo!") | |
} | |
function takeSnapshot() { | |
var img = document.createElement('img'); | |
var context; | |
var width = video.offsetWidth | |
, height = video.offsetHeight; | |
canvas = document.createElement('canvas'); | |
canvas.width = width; | |
canvas.height = height; | |
context = canvas.getContext('2d'); | |
context.drawImage(video, 0, 0, width, height); | |
img.src = canvas.toDataURL('image/png'); | |
document.body.appendChild(img); | |
} | |
</script> |
mau tanya kenapa kalo di server tidak mucul videonya untuk dapat di access ya?.
Apa ada pesan error?
Coba lihat di console javascript..
Pastikan juga menggunakan https
adakah cara lain agar bisa di jalankan di server?
sorry baru bales. kemarin sudah bisa. coba cek ssl-nya. setau saya harus secure access. jadi pake https:// bukan http saja.
kalau sekalian nyimpen file nya di folder gimana ya?
kalau sekalian nyimpen file nya di folder gimana ya?
up
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mau tanya kenapa kalo di server tidak mucul videonya untuk dapat di access ya?.