<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Multiview</title>
    <style>
        /* Estilo para mostrar los videos en una cuadrícula que se adapta al tamaño del contenedor */
        .video-container {
            display: grid;
            grid-template-columns: repeat(4, 1fr); /* 5 columnas por defecto en pantallas grandes */
            gap: 2px;
            max-width: 100%;
            margin: 0px;
            width: 100%;
            
            padding: 0px;
            box-sizing: border-box;
        }

        /* Contenedor individual para cada video */
        .video-item {
            position: relative;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            text-align: center;
            background-color: rgba(0, 0, 0, 0.5); /* Fondo semi-transparente */
            border-radius: 8px;
            overflow: hidden;
            height: 100%;
        }

        /* Estilo para centrar el texto dentro del cuadro */
        .video-item p {
            position: absolute;
            top: 35%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: white;
            font-size: 18px;
            font-weight: bold;
            z-index: 10;
            transition: opacity 0.3s ease;
        }

        /* Hacer que los videos ocupen todo el espacio de su celda de la cuadrícula */
        video {
            width: 100%; /* Se adapta al ancho de la celda */
            height: auto; /* Mantiene la proporción */
            object-fit: cover; /* Asegura que el video cubra el área sin distorsionarse */
        }

        /* Media queries para adaptar el número de columnas en diferentes tamaños de pantalla */
        @media (max-width: 1024px) {
            .video-container {
                grid-template-columns: repeat(3, 1fr); /* 3 columnas */
            }
        }

        @media (max-width: 600px) {
            .video-container {
                grid-template-columns: 1fr; /* 1 columna */
            }
        }
    </style>
</head>
<body style="background-color: #424242;font-family: sans-serif;">
    <div class="video-container">
        <div class="video-item" id="video-item1">
            <p>TRUJILLO</p>
            <video id="video1" autoplay muted ></video>
        </div>
        <div class="video-item" id="video-item2">
            <p>CHICLAYO</p>
            <video id="video2" autoplay muted ></video>
        </div>
        <div class="video-item" id="video-item3">
            <p>ICA</p>
            <video id="video3" autoplay muted ></video>
        </div>
        <div class="video-item" id="video-item4">
            <p>PIURA</p>
            <video id="video4" autoplay muted ></video>
        </div>
        <div class="video-item" id="video-item5">
            <p>TACNA</p>
            <video id="video5" autoplay muted ></video>
        </div>
        <div class="video-item" id="video-item6">
            <p>HUACHO</p>
            <video id="video6" autoplay muted ></video>
        </div>
        <div class="video-item" id="video-item7">
            <p>AREQUIPA</p>
            <video id="video7" autoplay muted ></video>
        </div>
        <div class="video-item" id="video-item8">
            <p>HUANCAYO</p>
            <video id="video8" autoplay muted ></video>
        </div>
        <div class="video-item" id="video-item9">
            <p>IQUITOS</p>
            <video id="video9" autoplay muted ></video>
        </div>
        <div class="video-item" id="video-item10">
            <p>TARAPOTO</p>
            <video id="video10" autoplay muted ></video>
        </div>
        <div class="video-item" id="video-item10">
            <p>CHIMBOTE</p>
            <video id="video10" autoplay muted ></video>
        </div>
        <div class="video-item" id="video-item10">
            <p>CAJAMARCA</p>
            <video id="video10" autoplay muted ></video>
        </div>
    </div>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>

    <script>
        // Lista de URLs M3U8
        const m3u8Urls = [
            'http://host1:8080/live/truJillo573gtFRG75dfd.m3u8',
            'http://host1:8080/live/chiclayo548rtshe7555stujjUY.m3u8',
            'http://host1:8080/live/iCa5ertshe7rw5ssujsUgX.m3u8',
            'http://host1:8080/live/piuRaherfhedsdfgssjvsfaX.m3u8',
            'http://host1:8080/live/tacna97Ybg&3CdfRGkikJ.m3u8',
            'http://host1:8080/live/huAcho897G54JsmkUytdA.m3u8',
            'http://host1:8080/live/areqiPahsgsHgsddgGGkdhsg.m3u8',
            'http://host1:8080/live/huanCayo765GydhjhGFHJK876.m3u8',
            'http://host1:8080/live/iquiTosUYHBF56654FGhbvcxfg756.m3u8',
            'http://host1:8080/live/tarPoto866Fhs8754skjghqaS.m3u8',
            'http://host1:8080/live/chimboteU4Hve56dvghjGhb74356.m3u8',
            'http://host1:8080/live/CAjArca562009shgsYTjdqaS.m3u8'
        ];

        // Inicializar cada video con HLS.js
        m3u8Urls.forEach((url, index) => {
            const videoElement = document.getElementById(`video${index + 1}`);
            const videoItem = document.getElementById(`video-item${index + 1}`);
            const nameElement = videoItem.querySelector('p');

            // Mostrar los nombres inicialmente
            nameElement.style.opacity = '1';

            // Ocultar nombre cuando el video comience a cargar o reproducirse
            videoElement.addEventListener('loadeddata', function() {
                nameElement.style.opacity = '0'; // Desaparece el nombre cuando el video empieza a cargar
            });

            videoElement.addEventListener('play', function() {
                nameElement.style.opacity = '0'; // Desaparece el nombre cuando el video comienza a reproducirse
            });

            if (Hls.isSupported()) {
                const hls = new Hls();
                hls.loadSource(url);
                hls.attachMedia(videoElement);
                hls.on(Hls.Events.MANIFEST_PARSED, function () {
                    videoElement.play();
                });
            } else if (videoElement.canPlayType('application/vnd.apple.mpegurl')) {
                videoElement.src = url; // Para navegadores como Safari que soportan HLS nativamente
                videoElement.play();
            }
        });
    </script>
</body>
</html>
