vivaplusdl/static/index.html

492 lines
17 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Viva++</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<style>
body {
background-color: #000;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.loader {
border: 1.5vw solid #333;
border-top: 1.5vw solid #3498db;
border-bottom: 1.5vw solid #3498db;
border-radius: 50%;
width: 10vw;
height: 10vw;
animation: spin 2s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.video-container {
display: none;
width: 100%;
justify-content: center;
align-items: center;
gap: 2vw;
}
.video-thumbnail {
border-radius: 8px;
transition: transform 0.3s ease;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
background-color: #444;
aspect-ratio: 16/9;
object-fit: cover;
}
.current-video {
width: 50vw;
z-index: 2;
box-shadow: 0 0 200px -10px #444;
}
.side-video {
width: 20vw;
opacity: 0.7;
z-index: 1;
}
.play-button {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 80px; /* Adjust size as needed */
height: 80px; /* Adjust size as needed */
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E");
background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent background */
background-repeat: no-repeat;
background-position: center;
background-size: 50%; /* Adjust icon size within button */
border-radius: 50%; /* Circular button */
cursor: pointer;
z-index: 3; /* Ensure it's above the video thumbnails */
border: 2px solid white;
box-shadow: 0 0 15px rgba(0,0,0,0.7);
}
#video-overlay-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: black;
z-index: 10000; /* Above other page content */
display: none; /* Initially hidden, JS will change to flex */
align-items: center;
justify-content: center;
}
#video-overlay-container .video-player {
width: 100%;
height: 100%;
display: block;
}
#video-overlay-container #back-button { /* Back button is now inside the container */
position: absolute;
top: 20px;
left: 20px;
z-index: 1; /* z-index relative to siblings in container */
padding: 10px 20px;
font-size: 16px;
background-color: rgba(0, 0, 0, 0.5);
color: white;
border: 1px solid white;
border-radius: 5px;
cursor: pointer;
opacity: 1; /* Visible by default */
transition: opacity 0.3s ease-in-out; /* Smooth transition */
}
#video-overlay-container #back-button.button-hidden {
opacity: 0; /* Class to hide the button */
}
#custom-video-controls {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
padding: 10px;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
z-index: 1; /* Above video, but below back button if it were in the same direct stacking context */
opacity: 1;
transition: opacity 0.3s ease-in-out;
box-sizing: border-box;
}
#custom-video-controls.controls-hidden {
opacity: 0;
}
#custom-play-pause-button {
background: none;
border: none;
color: white;
font-size: 1.5em; /* Adjust size as needed */
cursor: pointer;
padding: 5px 10px;
margin-right: 10px;
}
#custom-seek-bar {
flex-grow: 1;
cursor: pointer;
accent-color: #3498db; /* Optional: color for the seek bar thumb and progress */
}
/* Styles for TV remote focus indication */
.video-thumbnail:focus,
#back-button:focus {
outline: 3px solid #3498db !important; /* A clear blue outline */
box-shadow: 0 0 15px #3498db; /* A glow effect */
}
.nofocus:focus {
outline: none !important; /* Remove focus outline for elements with nofocus class */
}
</style>
<script>
function hideLoader() {
$(".loader").hide();
$(".video-container").css("display", "flex");
}
let currentVideo = null;
let videoElement = null;
let overlayContainer = null;
let inactivityTimer = null;
let backButton = null;
let customControls = null;
let playPauseButton = null;
let seekBar = null;
let videoPlaying = false;
function exitVideoPlayback() {
if (videoElement && videoElement.pause) {
videoElement.pause();
}
clearTimeout(inactivityTimer);
if (overlayContainer) {
overlayContainer.css('cursor', 'default');
overlayContainer.off('mousemove.inactivityControls'); // Remove session-specific listener
overlayContainer.hide(); // Hide instead of remove
}
$(document).off('fullscreenchange.videoPlayback webkitfullscreenchange.videoPlayback mozFullScreen.videoPlayback MSFullscreenChange.videoPlayback', handleFullscreenChange);
if (videoElement) {
$(videoElement).off('.currentVideo'); // Remove all namespaced video events
videoElement.src = ""; // Clear the source
videoElement.load(); // Important to ensure the video unloads
}
if (seekBar) { // seekBar is a jQuery object
seekBar.val(0);
seekBar.css('background', ''); // Reset seek bar style
}
updatePlayPauseButtonState(); // Update button to show play icon usually
// Attempt to exit fullscreen
if (document.fullscreenElement || document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement) {
if (document.exitFullscreen) {
document.exitFullscreen().catch(() => {});
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
// FOCUS: Return focus to the main view's play button
if ($(".video-container").is(":visible") && $('#play-button').length) {
$('#play-button').focus();
}
videoPlaying = false;
}
function showControlsAndResetTimer() {
if (backButton) backButton.removeClass('button-hidden');
if (customControls) customControls.removeClass('controls-hidden');
if (overlayContainer) overlayContainer.css('cursor', 'default');
clearTimeout(inactivityTimer);
inactivityTimer = setTimeout(function() {
if (backButton) backButton.addClass('button-hidden');
if (customControls) customControls.addClass('controls-hidden');
if (overlayContainer) overlayContainer.css('cursor', 'none');
}, 3000);
}
function handlePlayPauseClick() {
if (videoElement) {
if (videoElement.paused) {
videoElement.play();
} else {
videoElement.pause();
}
}
}
function updatePlayPauseButtonState() {
if (!playPauseButton || !videoElement) return;
if (videoElement.paused) {
playPauseButton.text('►');
} else {
playPauseButton.text('❚❚');
}
}
function handleVideoLoadedMetadata() {
if (seekBar && videoElement) {
seekBar.attr('max', videoElement.duration);
}
}
function handleVideoTimeUpdate() {
if (seekBar && videoElement && videoElement.duration) { // Check videoElement.duration to prevent NaN
seekBar.val(videoElement.currentTime);
const percentage = (videoElement.currentTime / videoElement.duration) * 100;
seekBar.css('background', `linear-gradient(to right, #3498db ${percentage}%, #555 ${percentage}%)`);
} else if (seekBar) {
seekBar.val(0); // Reset if duration is not available
}
}
function handleSeekBarInput() {
if (videoElement && seekBar) {
videoElement.currentTime = seekBar.val();
}
}
function handleFullscreenChange() {
const isActuallyFullscreen = document.fullscreenElement || document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement;
if (!isActuallyFullscreen && overlayContainer && overlayContainer.is(':visible')) {
// If fullscreen exited and overlay was visible, treat as exiting video playback
// This helps if user presses Esc.
exitVideoPlayback();
}
}
$(document).ready(function() {
// Initialize global selectors for static elements
overlayContainer = $("#video-overlay-container");
videoElement = overlayContainer.find(".video-player")[0];
backButton = overlayContainer.find("#back-button");
customControls = overlayContainer.find("#custom-video-controls");
playPauseButton = customControls.find("#custom-play-pause-button");
seekBar = customControls.find("#custom-seek-bar");
// Pre-set all thumbnails to a placeholder state
$(".video-thumbnail").attr("src", "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25' viewBox='0 0 16 9'%3E%3C/svg%3E");
$.getJSON("/api/homepage", function(data) {
currentVideo = data.currentVideo;
$("#current-thumb").attr("src", currentVideo.thumbnail);
hideLoader();
// FOCUS: Set initial focus on the main screen
if ($(".video-container").is(":visible") && $('#play-button').length) {
$('#play-button').focus();
}
})
// Attach event listeners that can be set up once for static controls
if (playPauseButton) playPauseButton.click(handlePlayPauseClick);
if (seekBar) seekBar.on('input', handleSeekBarInput);
if (backButton) backButton.click(exitVideoPlayback);
$("#play-button").click(function() {
if (currentVideo && currentVideo.url && videoElement && overlayContainer) {
// Set video source and load
videoElement.src = currentVideo.url;
videoElement.load();
// --- Setup Inactivity Controls (session-specific) ---
showControlsAndResetTimer(); // Initial call
updatePlayPauseButtonState(); // Initial state for the button
// Show overlay and request fullscreen
overlayContainer.css('display', 'flex');
const containerEl = overlayContainer[0];
if (containerEl.requestFullscreen) {
containerEl.requestFullscreen().catch(err => console.error("Error attempting to enable full-screen mode:", err));
} else if (containerEl.mozRequestFullScreen) {
containerEl.mozRequestFullScreen();
} else if (containerEl.webkitRequestFullscreen) {
containerEl.webkitRequestFullscreen();
} else if (containerEl.msRequestFullscreen) {
containerEl.msRequestFullscreen();
}
// FOCUS: Set focus in the video overlay
if (playPauseButton && playPauseButton.length) {
playPauseButton.focus();
}
videoElement.play().catch(err => console.error("Error attempting to play video:", err));
videoPlaying = true;
}
});
// --- Setup Custom Video Controls Events (session-specific for video element) ---
$(videoElement).on('play.currentVideo', updatePlayPauseButtonState);
$(videoElement).on('pause.currentVideo', updatePlayPauseButtonState);
$(videoElement).on('loadedmetadata.currentVideo', handleVideoLoadedMetadata);
$(videoElement).on('ended.currentVideo', exitVideoPlayback);
setInterval(handleVideoTimeUpdate, 1000/30);
// --- Setup Fullscreen Change Listener (session-specific) ---
$(document).off('fullscreenchange.videoPlayback webkitfullscreenchange.videoPlayback mozFullScreen.videoPlayback MSFullscreenChange.videoPlayback', handleFullscreenChange);
$(document).on('fullscreenchange.videoPlayback webkitfullscreenchange.videoPlayback mozFullScreen.videoPlayback MSFullscreenChange.videoPlayback', handleFullscreenChange);
overlayContainer.on('mousemove.inactivityControls', showControlsAndResetTimer);
// --- TV Remote/Keyboard Navigation ---
const mainViewFocusable = [$('#prev-thumb'), $('#play-button'), $('#next-thumb')].filter(el => el && el.length > 0);
const getOverlayViewFocusableElements = () => [backButton, playPauseButton, seekBar].filter(el => el && el.length > 0 && el.is(':visible'));
$(document).on('keydown', function(e) {
let isOverlayVisible = overlayContainer.is(':visible');
let activeFocusableSet;
if (isOverlayVisible) {
activeFocusableSet = getOverlayViewFocusableElements();
} else {
activeFocusableSet = mainViewFocusable;
}
if (!activeFocusableSet || activeFocusableSet.length === 0) return;
const focusedElement = $(document.activeElement);
let currentIndex = -1;
for (let i = 0; i < activeFocusableSet.length; i++) {
if (focusedElement.is(activeFocusableSet[i])) {
currentIndex = i;
break;
}
}
// Global key handling for overlay
if (isOverlayVisible) {
if (e.key === 'Backspace' || e.keyCode === 8) { // Backspace
e.preventDefault();
if (backButton && backButton.length) backButton.click();
return;
}
if (e.keyCode === 179) { // MediaPlayPause
e.preventDefault();
if (playPauseButton && playPauseButton.length) playPauseButton.click();
return;
}
if (e.keyCode === 178) { // MediaStop
e.preventDefault();
exitVideoPlayback();
return;
}
}
// If focus is not on a managed element, and not body/html, usually let it be.
// However, for certain keys like Enter, we might want a default action.
if (currentIndex === -1 && !focusedElement.is('body') && !focusedElement.is('html')) {
return;
}
let keyHandled = false;
switch (e.key || e.keyCode) {
case 'ArrowLeft':
case 37: // ArrowLeft
if (videoPlaying) {
videoElement.currentTime = Math.max(0, videoElement.currentTime - 5); // Seek back 5s
handleVideoTimeUpdate();
showControlsAndResetTimer();
} else if (currentIndex !== -1) {
let nextIndex = (currentIndex - 1 + activeFocusableSet.length) % activeFocusableSet.length;
activeFocusableSet[nextIndex].focus();
} else if (activeFocusableSet.length > 0) { // If nothing specific focused, focus last
activeFocusableSet[activeFocusableSet.length - 1].focus();
}
keyHandled = true;
break;
case 'ArrowRight':
case 39: // ArrowRight
if (videoPlaying) {
videoElement.currentTime = Math.min(videoElement.duration, videoElement.currentTime + 5); // Seek forward 5s
handleVideoTimeUpdate();
showControlsAndResetTimer();
} else if (currentIndex !== -1) {
let nextIndex = (currentIndex + 1) % activeFocusableSet.length;
activeFocusableSet[nextIndex].focus();
} else if (activeFocusableSet.length > 0) { // If nothing specific focused, focus first
activeFocusableSet[0].focus();
}
keyHandled = true;
break;
case 'Enter':
case 13: // Enter
if (videoPlaying) {
$('#play-button').click();
} else if (currentIndex !== -1) {
activeFocusableSet[currentIndex].click();
}
keyHandled = true;
break;
case 179: // MediaPlayPause (if not handled by global overlay section)
if (!isOverlayVisible && $('#play-button').length) {
$('#play-button').click();
keyHandled = true;
}
break;
}
if (keyHandled) {
e.preventDefault();
}
});
})
</script>
</head>
<body>
<div class="loader" id="loader"></div>
<div class="video-container">
<img id="prev-thumb" class="video-thumbnail side-video" alt="Previous Video" tabindex="0">
<img id="current-thumb" class="video-thumbnail current-video" alt="Current Video" tabindex="0">
<img id="next-thumb" class="video-thumbnail side-video" alt="Next Video" tabindex="0">
<div class="play-button" id="play-button" tabindex="0" role="button" aria-label="Play video"></div>
</div>
<!-- STATIC VIDEO OVERLAY STRUCTURE -->
<div id="video-overlay-container">
<video class="video-player"></video> <!-- no src, no autoplay, no controls initially -->
<button id="back-button" tabindex="0">Back</button>
<div id="custom-video-controls">
<button id="custom-play-pause-button" class="nofocus" tabindex="0"></button> <!-- Default to Play icon -->
<input type="range" id="custom-seek-bar" class="nofocus" value="0" step="any" tabindex="0" aria-label="Video seek bar" />
</div>
</div>
</body>
</html>