audio back and forth

This commit is contained in:
El-yazide MOHAMED 2025-06-07 08:06:05 +02:00
parent a9c1f21fe3
commit bdd82be393

View File

@ -76,16 +76,20 @@ function controlPlayback(speed) {
audioReverse.pause();
// Calcule la vitesse normalisée (sensibilité appliquée)
let normalizedSpeed = Math.min(MAX_SPEED, Math.abs(speed) * SENSITIVITY);
let normalizedSpeed = Math.min(MAX_SPEED, Math.max(0.5, Math.abs(speed) * SENSITIVITY));
// On lit dans le bon sens
if (speed > 0) {
audioForward.playbackRate = normalizedSpeed;
audioForward.currentTime = Math.min(audioForward.currentTime, audioForward.duration);
audioForward.playbackRate = normalizedSpeed; // Redémarrer la lecture si elle est arrivée à la fin
if (audioForward.currentTime >= audioForward.duration) {
audioForward.currentTime = 0;
}
audioForward.play();
} else {
audioReverse.playbackRate = normalizedSpeed;
audioReverse.currentTime = Math.min(audioReverse.currentTime, audioReverse.duration);
if (audioReverse.currentTime >= audioReverse.duration) {
audioReverse.currentTime = 0;
}
audioReverse.play();
}