<!DOCTYPE html>

<html lang="id">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>Kamera</title>


    <style>

        * {

            box-sizing: border-box;

        }


        body {

            margin: 0;

            background: #000;

            color: white;

            font-family: Arial, sans-serif;

            text-align: center;

        }


        h2 {

            margin: 20px 0;

        }


        video {

            width: 100%;

            max-width: 600px;

            height: 70vh;

            object-fit: cover;

            background: #111;

        }


        button {

            margin-top: 20px;

            padding: 15px 30px;

            border: 0;

            border-radius: 12px;

            background: #2196f3;

            color: white;

            font-size: 18px;

            font-weight: bold;

        }


        #status {

            margin-top: 15px;

            color: #aaa;

        }

    </style>

</head>


<body>


    <h2>📷 Kamera</h2>


    <video id="camera" autoplay playsinline></video>


    <br>


    <button onclick="startCamera()">

        📷 Aktifkan Kamera

    </button>


    <div id="status">

        Kamera belum aktif

    </div>


    <script>

        async function startCamera() {


            const video = document.getElementById("camera");

            const status = document.getElementById("status");


            try {


                const stream = await navigator.mediaDevices.getUserMedia({

                    video: {

                        facingMode: {

                            ideal: "environment"

                        }

                    },

                    audio: false

                });


                video.srcObject = stream;


                status.innerText = "✅ Kamera aktif";


            } catch (error) {


                console.error(error);


                status.innerText =

                    "❌ Kamera tidak dapat digunakan: " + error.message;

            }

        }

    </script>


</body>

</html>