GR-Jukebox/display2.html
2024-08-06 20:52:02 -04:00

113 lines
3.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Now Playing</title>
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.0/socket.io.js">-->
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 0;
background-color: #0f0f0f;
display: flex;
align-items: center;
height: 100vh;
margin: 0;
flex-direction: column;
}
h1 {
color: #999;
font-size: 5vw;
}
span{
color:#999;
font-size: 1vw;
margin: 1vw;
}
#now-playing {
font-size: 3vw;
color: #007bff;
}
.progress-container {
display: flex;
align-items: center;
justify-content: space-between;
position: relative;
height: 5vh;
width: 75vw;
}
.progress-bar {
width: 100%;
background-color: #eee;
height: 2vh;
border-radius: 1vh;
overflow: hidden;
}
.progress {
height: 2vh;
background-color: #007BFF;
width: 0%;
border-radius: 1vh;
transition: width 0.5s ease;
}
#album-art {
height: 20vh;
width: auto;
border-radius: 1vh;
margin-bottom: 1vh;
}
</style>
</head>
<body>
<h1>Now Playing</h1>
<img id="album-art" src="mao.jpg">
<div id="now-playing">Nothing is playing</div>
<h1></h1>
<div class="progress-container">
<span id="current-time">0:00</span>
<div class="progress-bar">
<div class="progress" id="progress" style="width: 0%;"></div>
</div>
<span id="duration">4:00</span>
</div>
<script src="https://cdn.socket.io/4.0.0/socket.io.min.js"></script>
<script>
const socket = io(); // Connect to WebSocket server
socket.on('connect', function() {
console.log('Connected to WebSocket server!');
loadCurrent();
});
socket.on('current', function(data) {
console.log(data);
document.getElementById('now-playing').textContent = data.title || 'Nothing is playing';
});
socket.on('progress_update', function(data) {
updateProgressBar(data.percentage);
document.getElementById('current-time').innerText = formatTime(data.current_time);
document.getElementById('duration').innerText = formatTime(data.total_duration);
});
function updateProgressBar(percentage) {
const progressBar = document.getElementById('progress');
progressBar.style.width = percentage + '%';
}
function formatTime(seconds) {
const min = Math.floor(seconds / 60);
const sec = seconds % 60;
return `${min}:${sec < 10 ? '0' : ''}${sec}`;
}
function loadCurrent() {
socket.emit('current_song');
}
</script>
</body>
</html>