rewind encore

This commit is contained in:
El-yazide MOHAMED 2025-06-07 20:59:01 +02:00
parent 10e8782798
commit 82ce27c10d
3 changed files with 5 additions and 142 deletions

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>

View File

@ -19,8 +19,7 @@ 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();
@ -66,7 +65,6 @@ socket.on('position', (position) => {
}, 300);
});
/*
// 4. Fonctions
function togglePlay() {
@ -149,65 +147,4 @@ 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();
}
});

View File

@ -1,4 +1,4 @@
/* const express = require('express');
const express = require('express');
const { createServer } = require('node:http');
// socket
const { Server } = require('socket.io');
@ -69,78 +69,4 @@ io.on('connection', (socket) => {
server.listen(port, () => {
console.log(`Example app listening on port ${port}`)
}) */
const express = require('express');
const http = require('http');
const socketIo = require('socket.io');
const player = require('play-sound')({ player: 'mpg123' }); // forcer mpg123
const app = express();
const server = http.createServer(app);
const io = socketIo(server);
const SerialPort = require('serialport');
const ReadlineParser = require('@serialport/parser-readline');
const portName = "/dev/ttyUSB0"; // adapte selon ta config
const arduinoSerialPort = new SerialPort(portName, { baudRate: 115200 });
const parser = arduinoSerialPort.pipe(new ReadlineParser({ delimiter: '\n' }));
parser.on('data', (data) => {
console.log('Données reçues Arduino:', data.trim());
io.emit('position', data.trim()); // envoi à tous les clients
});
io.on('connection', (socket) => {
console.log('Client connecté');
// Ici tu peux gérer d'autres events socket si besoin
});
app.use(express.static('assets')); // dossier public pour fichiers front
let currentAudioProcess = null;
io.on('connection', (socket) => {
console.log('Client connecté');
socket.on('play-sound', (filename) => {
console.log('Lecture demandée:', filename);
// Stopper si un son est déjà joué
if (currentAudioProcess) {
console.log('Arrêt du son précédent');
currentAudioProcess.kill();
currentAudioProcess = null;
}
// Lancer la lecture avec mpg123
const path = require('path');
const filePath = path.join(__dirname, 'node-server', 'sounds', filename);
console.log('Chemin complet du fichier:', filePath);
currentAudioProcess = player.play(filePath, (err) => {
if (err && !err.killed) {
console.error('Erreur lecture audio:', err);
}
currentAudioProcess = null;
});
});
socket.on('stop-sound', () => {
if (currentAudioProcess) {
currentAudioProcess.kill();
currentAudioProcess = null;
console.log('Lecture arrêtée');
}
});
socket.on('disconnect', () => {
console.log('Client déconnecté');
});
});
server.listen(3000, () => {
console.log('Serveur démarré sur http://localhost:3000');
});
})