var videoElement = null; var captionEl = null; var videos = [ { "url": "/videos/vQue es.mp4", "text": "Que é a Festa do Marisco? Desliza para saber máis.", "finalText": "Queres saber máis? Desliza cara arriba para afondar nas nosas raíces históricas." }, { "url": "/videos/vQue es 2.mp4", "text": "Descubre o evento da man dos nosos visitantes.", "finalText": "Tes curiosidade por como as nosas tradicións se mantiveron vivas? Explora máis sobre a nosa herdanza culinaria, desliza." }, { "url": "/videos/vHistoria.mp4", "text": "Viaxa a través do tempo para explorar a nosa historia.", "finalText": "Tes curiosidade por como as nosas tradicións se mantiveron vivas? Explora máis sobre a nosa herdanza culinaria." }, { "url": "/videos/vTradicion.mp4", "text": "Aprende sobre a nosa tradición transmitida de xeración en xeración e como influíu no noso enfoque culinario.", "finalText": "Fascinado pola tradición? Coñece como os nosos chefs empregan estes métodos tradicionais hoxe." }, { "url": "/videos/vvideo1.mp4", "text": "Explora as características únicas da Navalla, un marisco esencial na nosa cociña.", "finalText": "Interesado noutros mariscos exquisitos? Non perdas o noso próximo vídeo sobre o Arroz de Mariscos." }, { "url": "/videos/vvideo2.mp4", "text": "Deléitate co noso Arroz de Mariscos, unha combinación perfecta de sabores que captura a esencia do océano.", "finalText": "Tes curiosidade por máis delicias? Descubre o sabor fresco e auténtico do Mexillón no noso seguinte vídeo." }, { "url": "/videos/vvideo3.mp4", "text": "Somérxete no sabor vibrante do Mexillón, un compoñente vital da nosa oferta culinaria.", "finalText": "Fascinado polos sabores do mar? A Zamburiña agárdate no próximo vídeo para sorprenderte." }, { "url": "/videos/vvideo4.mp4", "text": "Experimenta o sabor suave e delicado da Zamburiña, unha favorita entre gourmets e chefs.", "finalText": "Interesado en explorar máis sobre os nosos métodos de cociña? Descubre como preparamos o Polbo no seguinte vídeo." }, { "url": "/videos/vvideo5.mp4", "text": "Descubre as diversas formas de preparar o Polbo e como cada técnica realza os seus sabores únicos.", "finalText": "Grazas por acompañarnos nesta viaxe culinaria. Agardamos que gozaras descubrindo a nosa cociña tanto como nós gozamos preparándoa para ti." } ]; // ── Estado ── var currentVideoIndex = 0; var userWantsSound = false; var progressInterval = null; var isTouch = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0); // ── Progreso (story bars) ── function initProgressBars() { var bar = document.getElementById('progress-bar'); if (!bar) return; bar.innerHTML = ''; for (var i = 0; i < videos.length; i++) { var seg = document.createElement('div'); seg.className = 'progress-segment'; seg.id = 'seg-' + i; var fill = document.createElement('div'); fill.className = 'fill'; seg.appendChild(fill); bar.appendChild(seg); } } function updateProgressBars() { if (progressInterval) { clearInterval(progressInterval); progressInterval = null; } for (var i = 0; i < videos.length; i++) { var seg = document.getElementById('seg-' + i); if (!seg) continue; var fill = seg.querySelector('.fill'); if (i < currentVideoIndex) { seg.classList.add('done'); fill.style.width = '100%'; } else if (i === currentVideoIndex) { seg.classList.remove('done'); fill.style.width = '0%'; // Animar fill según progreso real del vídeo (function(f) { progressInterval = setInterval(function() { if (!videoElement || !videoElement.duration) return; var pct = (videoElement.currentTime / videoElement.duration) * 100; f.style.width = Math.min(pct, 100) + '%'; if (pct >= 100) { clearInterval(progressInterval); progressInterval = null; } }, 300); })(fill); } else { seg.classList.remove('done'); fill.style.width = '0%'; } } } // ── Contador ── function updateCounter() { var el = document.getElementById('video-counter'); if (el) el.textContent = (currentVideoIndex + 1) + ' / ' + videos.length; } // ── Caption ── function showCaption(text) { if (!captionEl) return; captionEl.classList.add('hide'); setTimeout(function() { captionEl.innerHTML = text || ''; captionEl.classList.remove('hide'); // Auto-ocultar tras 15s setTimeout(function() { captionEl.classList.add('hide'); }, 15000); }, 300); } // ── Sonido: sincronizar icono ── function syncSoundIcon() { var icon = document.getElementById('sound-icon'); if (!icon || !videoElement) return; icon.className = videoElement.muted ? 'fas fa-volume-mute' : 'fas fa-volume-up'; } // ── Reproducción ── function changeVideo(fadeDir) { if (!videoElement) return; // Fade out videoElement.classList.add('fading'); setTimeout(function() { // Configurar vídeo videoElement.muted = !userWantsSound; videoElement.autoplay = true; videoElement.setAttribute('playsinline', ''); videoElement.setAttribute('webkit-playsinline', ''); videoElement.onended = null; videoElement.src = videos[currentVideoIndex].url; videoElement.currentTime = 0; videoElement.load(); // Fade in videoElement.classList.remove('fading'); // UI updateCounter(); updateProgressBars(); syncSoundIcon(); showCaption(videos[currentVideoIndex].text); // Al terminar el vídeo: mostrar texto final videoElement.onended = function() { showCaption(videos[currentVideoIndex].finalText); }; // Autoplay var p = videoElement.play(); if (p && typeof p.then === 'function') { p.catch(function() { /* bloqueado por política del navegador */ }); } }, 220); } // ── Controles globales ── function playVideo() { if (!videoElement) return; if (videoElement.muted) { userWantsSound = true; videoElement.muted = false; if (videoElement.volume === 0) videoElement.volume = 0.6; syncSoundIcon(); videoElement.play().catch(function(){}); return; } if (videoElement.paused) { videoElement.play().catch(function(){}); } else { videoElement.pause(); } } function nextVideo() { currentVideoIndex = (currentVideoIndex + 1) % videos.length; changeVideo('up'); } function previousVideo() { currentVideoIndex = (currentVideoIndex - 1 + videos.length) % videos.length; changeVideo('down'); } // ── Inicialización ── document.addEventListener('DOMContentLoaded', function() { videoElement = document.getElementById('current-video'); captionEl = document.getElementById('caption-text'); initProgressBars(); // ── MÓVIL: swipe + unmute automático ── if (isTouch && videoElement) { var touchstartY = 0, touchstartX = 0, THRESHOLD = 48; document.getElementById('tour-wrapper').addEventListener('touchstart', function(e) { touchstartY = e.changedTouches[0].clientY; touchstartX = e.changedTouches[0].clientX; }, { passive: true }); document.getElementById('tour-wrapper').addEventListener('touchend', function(e) { var dy = e.changedTouches[0].clientY - touchstartY; var dx = e.changedTouches[0].clientX - touchstartX; var tapX = e.changedTouches[0].clientX; // Ignorar si el toque fue sobre botones, top-bar, etc. var target = e.target; if (target.closest('#action-buttons') || target.closest('#top-bar') || target.closest('#nav-arrows')) { return; } if (Math.abs(dy) > Math.abs(dx) && Math.abs(dy) > THRESHOLD) { // Swipe vertical: arriba → siguiente, abajo → anterior if (dy < 0) { nextVideo(); } else { previousVideo(); } } else if (Math.abs(dy) < 12 && Math.abs(dx) < 12) { // Tap corto: mitad izquierda → anterior, mitad derecha → siguiente if (tapX < window.innerWidth / 2) { previousVideo(); } else { nextVideo(); } } }, { passive: true }); // Primera interacción: desmutear var unmuteOnce = function() { if (!userWantsSound) { userWantsSound = true; videoElement.muted = false; if (videoElement.volume === 0) videoElement.volume = 0.6; syncSoundIcon(); videoElement.play().catch(function(){}); } window.removeEventListener('touchend', unmuteOnce, true); }; window.addEventListener('touchend', unmuteOnce, true); // Swipe tip var swipeTip = document.getElementById('swipe-tip'); if (swipeTip) { swipeTip.style.display = 'flex'; var hideTip = function() { swipeTip.classList.add('hide'); setTimeout(function() { if (swipeTip.parentNode) swipeTip.parentNode.removeChild(swipeTip); }, 500); document.getElementById('tour-wrapper').removeEventListener('touchstart', hideTip, true); }; setTimeout(hideTip, 5000); document.getElementById('tour-wrapper').addEventListener('touchstart', hideTip, { once: true, capture: true }); } } // ── DESKTOP: teclado + click para desmutear ── if (!isTouch) { document.addEventListener('keydown', function(e) { switch (e.key) { case 'ArrowDown': case 'PageDown': e.preventDefault(); nextVideo(); break; case 'ArrowUp': case 'PageUp': e.preventDefault(); previousVideo(); break; case ' ': case 'Spacebar': e.preventDefault(); playVideo(); break; case 'm': case 'M': var btn = document.getElementById('sound-button'); if (btn) btn.click(); break; } }); // Click en el vídeo: desmutea / pausa-play videoElement.addEventListener('click', function() { if (videoElement.muted) { userWantsSound = true; videoElement.muted = false; if (videoElement.volume === 0) videoElement.volume = 0.6; syncSoundIcon(); videoElement.play().catch(function(){}); } else { if (videoElement.paused) { videoElement.play().catch(function(){}); } else { videoElement.pause(); } } }); } // Cargar primer vídeo changeVideo(); });