DEV Community

Canabi
Canabi

Posted on

How to open a Camera on an HTML Site?

To open a camera on an HTML site, you usually use the getUserMedia() API offered by HTML5. This API provides access to the cameras and microphones on the user's device. Here is a simple example:

`<!DOCTYPE html>




Kamera Açma


Kamera Açma


<script>
    // Kameraya erişimi kontrol et
    navigator.mediaDevices.getUserMedia({ video: true })
        .then(function (stream) {
            var video = document.getElementById('videoElement');
            // Video elementine akışı atayın
            video.srcObject = stream;
        })
        .catch(function (err) {
            console.log("Kamera erişim hatası: " + err);
        });
</script>



`

This code creates a video element to display images from the camera into a video tag and provides access to the camera with getUserMedia(). When the user visits this page, the browser will ask for permission to access the camera, and if the user gives permission, the camera image will be transferred to the video element.

Top comments (0)