This commit is contained in:
2025-06-07 20:20:14 +02:00
parent 21f18d1b2a
commit f236665829
3 changed files with 118 additions and 5 deletions
+2 -2
View File
@@ -43,9 +43,9 @@
<button id="forward">10s +</button>
</div>
<audio id="audio"
<!-- <audio id="audio"
src="muddy_files.mp3"
data-reverse-src="muddy_files_reverse.mp3"></audio>
data-reverse-src="muddy_files_reverse.mp3"></audio> -->
</main>
+63 -1
View File
@@ -19,7 +19,8 @@ const rotationsPerTrack = 3; // tours complets du vinyle sur toute la durée
let currentRotation = 0; // rotation en degrés actuelle du vinyle
// 3. Connexion Socket.io
const socket = io();
/* const socket = io();
socket.on('position', (position) => {
const now = Date.now();
@@ -147,4 +148,65 @@ audio.addEventListener('ended', () => {
} else {
isPlaying = false;
}
}); */
const socket = io();
let isPlaying = false;
const rotationsPerTrack = 3;
let currentRotation = 0;
// Valeurs fictives pour durée, car tu ne peux plus récupérer la durée côté client
const DURATION = 96; // durée en secondes (1:36)
// Simulation simple du temps qui passe côté client pour la rotation du vinyle
let currentTime = 0;
let animationFrameId;
function playTrack() {
socket.emit('play-sound', 'muddy_files.mp3');
isPlaying = true;
startVinylRotation();
}
function stopTrack() {
socket.emit('stop-sound');
isPlaying = false;
stopVinylRotation();
currentTime = 0;
updateVinylRotation();
}
function startVinylRotation() {
function update() {
if (isPlaying) {
currentTime += 0.1; // avance temps fictif
if (currentTime > DURATION) {
currentTime = 0; // boucle simple
}
updateVinylRotation();
animationFrameId = requestAnimationFrame(update);
}
}
update();
}
function stopVinylRotation() {
cancelAnimationFrame(animationFrameId);
}
function updateVinylRotation() {
currentRotation = (currentTime / DURATION) * 360 * rotationsPerTrack;
vinyl.style.transform = `rotate(${currentRotation}deg)`;
}
// Exemple : lancer / arrêter à chaque clic
vinyl.addEventListener('click', () => {
if (isPlaying) {
stopTrack();
} else {
playTrack();
}
});