-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
29 lines (28 loc) · 1017 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
let currentAudio = null;
let currentButton = null;
function toggleMusic(musicFile, button) {
if (currentAudio && currentAudio.src.includes(musicFile)) {
if (currentAudio.paused) {
currentAudio.play();
button.classList.add('pause');
button.textContent = 'Pause';
} else {
currentAudio.pause();
button.classList.remove('pause');
button.textContent = `Musique ${button.textContent.split(' ')[1]}`;
}
} else {
if (currentAudio) {
currentAudio.pause();
currentButton.classList.remove('pause');
currentButton.textContent = `Musique ${currentButton.textContent.split(' ')[1]}`;
}
const audioPlayer = document.getElementById('audio-player');
audioPlayer.src = musicFile;
audioPlayer.play();
button.classList.add('pause');
button.textContent = 'Pause';
currentAudio = audioPlayer;
currentButton = button;
}
}