182 lines
6.3 KiB
HTML
182 lines
6.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Media Player</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 0;
|
|
background-color: black;
|
|
color: white;
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100vh;
|
|
}
|
|
.playlist-container {
|
|
flex: 1;
|
|
overflow: hidden;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
background-color: black;
|
|
}
|
|
ul {
|
|
list-style-type: none;
|
|
padding: 0;
|
|
display: none; /* Hide the playlist list */
|
|
}
|
|
.controls-wrapper {
|
|
display: flex;
|
|
justify-content: center;
|
|
width: 33.33%; /* 1/3 of the page width */
|
|
margin: 0 auto;
|
|
transition: opacity 0.5s ease; /* Smooth fade effect */
|
|
}
|
|
.controls-wrapper.hidden {
|
|
opacity: 0; /* Hide the buttons */
|
|
pointer-events: none; /* Disable interaction when hidden */
|
|
}
|
|
.controls {
|
|
display: flex;
|
|
justify-content: center;
|
|
gap: 15px; /* Space between buttons */
|
|
padding: 10px;
|
|
background-color: #222;
|
|
}
|
|
button {
|
|
margin: 5px;
|
|
padding: 10px;
|
|
background-color: #444;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
font-size: 20px;
|
|
}
|
|
button:hover {
|
|
background-color: #666;
|
|
}
|
|
button i {
|
|
pointer-events: none;
|
|
}
|
|
img, video {
|
|
max-width: 100%;
|
|
max-height: 100%;
|
|
}
|
|
</style>
|
|
<!-- Add Font Awesome for icons -->
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
|
</head>
|
|
<body>
|
|
<div class="playlist-container" id="playlist-container">
|
|
<!-- Content will be dynamically added here -->
|
|
</div>
|
|
<div class="controls-wrapper" id="controls-wrapper">
|
|
<div class="controls">
|
|
<button onclick="previousMedia()"><i class="fas fa-step-backward"></i></button> <!-- Previous -->
|
|
<button onclick="loadPlaylist()"><i class="fas fa-sync-alt"></i></button> <!-- Refresh Playlist -->
|
|
<button onclick="playMedia()"><i class="fas fa-play"></i></button> <!-- Play -->
|
|
<button onclick="nextMedia()"><i class="fas fa-step-forward"></i></button> <!-- Next -->
|
|
<button onclick="stopMedia()"><i class="fas fa-stop"></i></button> <!-- Stop -->
|
|
<button onclick="goToSettings()"><i class="fas fa-cog"></i></button> <!-- Settings -->
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const apiBase = 'http://localhost:1025'; // Update to match your Flask app's port
|
|
const playlistContainer = document.getElementById('playlist-container');
|
|
let playlist = [];
|
|
let currentIndex = 0;
|
|
let playbackInterval;
|
|
|
|
// Function to load the playlist from updated_playlist.json
|
|
async function loadPlaylist() {
|
|
try {
|
|
const response = await fetch(`${apiBase}/updated_playlist.json`);
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to load playlist: ${response.statusText}`);
|
|
}
|
|
const data = await response.json();
|
|
playlist = data; // Use the updated playlist
|
|
console.log("Loaded playlist:", playlist); // Debug log
|
|
startPlaylist(); // Start playing the playlist after loading
|
|
} catch (error) {
|
|
console.error("Error loading playlist:", error);
|
|
}
|
|
}
|
|
|
|
// Function to start playing the playlist
|
|
function startPlaylist() {
|
|
if (playlist.length === 0) {
|
|
console.error("No items in the playlist.");
|
|
return;
|
|
}
|
|
playCurrentItem();
|
|
}
|
|
|
|
// Function to play the current item in the playlist
|
|
function playCurrentItem() {
|
|
if (currentIndex >= playlist.length) {
|
|
currentIndex = 0; // Loop back to the beginning
|
|
}
|
|
|
|
const currentItem = playlist[currentIndex];
|
|
playlistContainer.innerHTML = ''; // Clear the container
|
|
|
|
if (currentItem.type === 'image') {
|
|
const img = document.createElement('img');
|
|
img.src = currentItem.url;
|
|
playlistContainer.appendChild(img);
|
|
|
|
// Display the image for the specified duration
|
|
playbackInterval = setTimeout(() => {
|
|
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);
|
|
|
|
// Play the video and move to the next item after it ends
|
|
video.onended = () => {
|
|
currentIndex++;
|
|
playCurrentItem();
|
|
};
|
|
}
|
|
}
|
|
|
|
// Function to stop playback
|
|
function stopMedia() {
|
|
clearTimeout(playbackInterval);
|
|
playlistContainer.innerHTML = ''; // Clear the container
|
|
}
|
|
|
|
// Function to play the previous item
|
|
function previousMedia() {
|
|
stopMedia();
|
|
currentIndex = (currentIndex - 1 + playlist.length) % playlist.length;
|
|
playCurrentItem();
|
|
}
|
|
|
|
// Function to play the next item
|
|
function nextMedia() {
|
|
stopMedia();
|
|
currentIndex = (currentIndex + 1) % playlist.length;
|
|
playCurrentItem();
|
|
}
|
|
|
|
function goToSettings() {
|
|
window.location.href = '/static/settings.html';
|
|
}
|
|
|
|
// Load playlist on page load
|
|
loadPlaylist();
|
|
</script>
|
|
</body>
|
|
</html> |