Files
ds-play/app/static/settings.html
2025-05-12 10:14:22 +03:00

213 lines
8.0 KiB
HTML
Executable File

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Settings</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: black; /* Set background to black */
color: white; /* Set text color to white */
}
label {
display: block;
margin: 10px 0 5px;
}
input, select {
width: 100%;
padding: 8px;
margin-bottom: 10px;
background-color: #333; /* Dark background for inputs */
color: white; /* White text for inputs */
border: 1px solid #555; /* Subtle border for inputs */
border-radius: 4px; /* Rounded corners */
}
button {
padding: 10px 15px;
background-color: #444; /* Dark button background */
color: white; /* White text for buttons */
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #666; /* Lighter background on hover */
}
.home-button {
position: fixed;
bottom: 20px;
right: 20px;
background-color: #444; /* Dark background for home button */
color: white;
border: none;
border-radius: 5px;
padding: 10px 15px;
cursor: pointer;
}
.home-button:hover {
background-color: #666; /* Lighter background on hover */
}
</style>
</head>
<body>
<h1>Settings</h1>
<form id="settings-form">
<label for="player_orientation">Player Orientation</label>
<select id="player_orientation" name="player_orientation">
<option value="portrait">Portrait</option>
<option value="landscape">Landscape</option>
</select>
<label for="player_name">Player Name</label>
<input type="text" id="player_name" name="player_name">
<label for="quickconnect_code">QuickConnect Code</label>
<input type="text" id="quickconnect_code" name="quickconnect_code">
<label for="server_address">Server Address</label>
<input type="text" id="server_address" name="server_address">
<label for="port">Port</label>
<input type="number" id="port" name="port">
<button type="button" onclick="saveConfig()">Save Settings</button>
</form>
<!-- Home button -->
<button class="home-button" onclick="goHome()">🏠 Home</button>
<script>
const apiBase = '/api';
let appConfig = {}; // Global variable to store app configuration
let playlist = []; // Global variable for the playlist
let currentIndex = 0; // Current index in the playlist
let playbackInterval;
let isPaused = false;
// Load configuration on page load
async function loadConfig() {
try {
const response = await fetch('/static/app_config.json'); // Fetch app_config.json
if (!response.ok) {
throw new Error(`Failed to load configuration: ${response.statusText}`);
}
appConfig = await response.json(); // Store configuration in the global variable
console.log("App configuration loaded:", appConfig); // Debug log
} catch (error) {
console.error("Error loading app configuration:", error);
}
}
// Load playlist from updated_playlist.json
async function loadPlaylist() {
try {
const response = await fetch('/updated_playlist.json'); // Fetch updated_playlist.json
if (!response.ok) {
throw new Error(`Failed to load playlist: ${response.statusText}`);
}
playlist = await response.json(); // Store playlist in the global variable
console.log("Updated playlist loaded:", playlist); // Debug log
} catch (error) {
console.error("Error loading updated playlist:", error);
}
}
// Play the current item in the playlist
async function playCurrentItem() {
if (currentIndex >= playlist.length) {
currentIndex = 0; // Loop back to the beginning
}
const currentItem = playlist[currentIndex];
console.log("Playing current item:", currentItem); // Debug log
const playlistContainer = document.getElementById('playlist-container');
playlistContainer.innerHTML = ''; // Clear the container
if (currentItem.type === 'image') {
const img = document.createElement('img');
img.src = currentItem.url;
// Check the orientation of the image and adjust the object-fit property
const image = new Image();
image.src = currentItem.url;
image.onload = () => {
const isImageLandscape = image.width > image.height;
if (
(appConfig.player_orientation === 'landscape' && !isImageLandscape) ||
(appConfig.player_orientation === 'portrait' && isImageLandscape)
) {
img.style.objectFit = 'contain'; // Show the full image without cropping
} else {
img.style.objectFit = 'cover'; // Crop to fit the container
}
};
playlistContainer.appendChild(img);
// Display the image for the specified duration
playbackInterval = setTimeout(() => {
if (!isPaused) {
currentIndex++;
playCurrentItem();
}
}, currentItem.duration * 1000);
} else if (currentItem.type === 'video') {
const video = document.createElement('video');
video.src = currentItem.url;
video.autoplay = true;
video.controls = false;
playlistContainer.appendChild(video);
// Ensure the video starts playing
video.play().catch(error => {
console.error("Error starting video playback:", error);
});
// Play the video and move to the next item after it ends
video.onended = () => {
if (!isPaused) {
currentIndex++;
playCurrentItem();
}
};
}
}
// Initialize the page
async function initialize() {
await loadConfig(); // Load app configuration
await loadPlaylist(); // Load playlist
playCurrentItem(); // Start playing the playlist
}
// Start initialization when the page loads
window.onload = initialize;
// Save configuration
async function saveConfig() {
const config = {
player_orientation: document.getElementById('player_orientation').value,
player_name: document.getElementById('player_name').value,
quickconnect_code: document.getElementById('quickconnect_code').value,
server_address: document.getElementById('server_address').value,
port: parseInt(document.getElementById('port').value, 10)
};
await fetch(`${apiBase}/config`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(config)
});
alert('Settings saved successfully!');
}
// Navigate back to the home page
function goHome() {
window.location.href = '/';
}
</script>
</body>
</html>