From 037be29498d73acbf2e72a0728706d002e5e46f5 Mon Sep 17 00:00:00 2001 From: Michael Verdi Date: Wed, 30 Jul 2025 09:03:20 -0500 Subject: [PATCH] Phase 1: Enable 2D video playback when VR is unavailable - Remove automatic video hiding on page load - Show video element by default for 2D viewing - Enable play button for regular video playback when VR is not supported - Hide video only when entering VR mode, show when exiting - Maintain existing VR functionality when supported - Button text always comes from HTML, never modified by JavaScript --- vr180-player.js | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/vr180-player.js b/vr180-player.js index 7391fc8..5b42f1a 100644 --- a/vr180-player.js +++ b/vr180-player.js @@ -83,10 +83,6 @@ document.addEventListener('DOMContentLoaded', () => { videoElement = document.getElementById('vr180'); playBtn = document.getElementById('playBtn'); - if (videoElement) { - videoElement.style.display = 'none'; - } - if (!videoElement || !playBtn) { console.error("CRITICAL_ERROR_DOM: Essential HTML elements (video or VR button) not found."); return; @@ -104,16 +100,18 @@ document.addEventListener('DOMContentLoaded', () => { init(); } else { playBtn.dataset.xrSupported = "false"; - playBtn.disabled = true; + // Enable button for regular video playback when VR is not supported + playBtn.disabled = false; } }).catch(err => { console.error("XR Support Check Error:", err); - playBtn.disabled = true; + // Enable button for regular video playback when VR check fails + playBtn.disabled = false; }); } else { - // If navigator.xr itself is not available, VR is not supported + // If navigator.xr itself is not available, enable button for regular video playback if (playBtn) { - playBtn.disabled = true; + playBtn.disabled = false; } } }); @@ -764,8 +762,15 @@ async function handleEnterVRButtonClick() { console.error("Video element not found for VR button click."); return; } - // If xrSession exists, we want to exit. If null, we want to enter. - await actualSessionToggle(); + + // Check if VR is supported + if (playBtn.dataset.xrSupported === "true") { + // VR is supported - use VR functionality + await actualSessionToggle(); + } else { + // VR is not supported - use regular video playback + togglePlayPause(); + } } async function actualSessionToggle() { @@ -805,6 +810,11 @@ async function actualSessionToggle() { xrSession.addEventListener('end', onVRSessionEnd); + // Hide the regular video element when entering VR + if (video) { + video.style.display = 'none'; + } + if (video && (video.paused || video.ended)) { try { await video.play(); @@ -887,8 +897,10 @@ function onVRSessionEnd(event) { } } - // No need to change button text when exiting VR as it should keep its original text - + // Show the regular video element when exiting VR + if (video) { + video.style.display = ''; + } if (video && !video.paused) { video.pause();