Skip to content

Commit

Permalink
👌 IMPROVE: app audio
Browse files Browse the repository at this point in the history
  • Loading branch information
yoanbernabeu committed Sep 22, 2024
1 parent 68de5c7 commit 49855b3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
text-align: center;
padding: 20px;
margin: 0;
position: relative;
overflow: hidden;
}
h1 {
color: #e94560;
}
.container {
max-width: 500px;
margin: 0 auto;
position: relative;
z-index: 1;
}
label {
display: block;
Expand Down Expand Up @@ -101,7 +105,9 @@ <h1>Le Cristal des Rêves - Minuteur</h1>
let easierMode = false;
let songSegments = [];
let currentSongIndex = 0;
let audioElement = null;
let audioContext;
let audioElement;
let audioSource;

const durationInput = document.getElementById('duration');
const startButton = document.getElementById('startButton');
Expand Down Expand Up @@ -138,6 +144,9 @@ <h1>Le Cristal des Rêves - Minuteur</h1>
// Diviser le temps total en 5 segments pour les chansons
calculateSongSegments();

// Initialiser l'AudioContext
audioContext = new (window.AudioContext || window.webkitAudioContext)();

// Démarrer la première chanson
currentSongIndex = 0;
playCurrentSong();
Expand Down Expand Up @@ -202,6 +211,11 @@ <h1>Le Cristal des Rêves - Minuteur</h1>
const songNumber = ('0' + (currentSongIndex + 1)).slice(-2);
audioElement = new Audio(`song${songNumber}.mp3`);
audioElement.loop = true;

// Utiliser l'AudioContext pour jouer l'audio
audioSource = audioContext.createMediaElementSource(audioElement);
audioSource.connect(audioContext.destination);

audioElement.play().catch(error => {
console.error('Erreur lors de la lecture de la piste audio :', error);
});
Expand Down

0 comments on commit 49855b3

Please sign in to comment.