-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript2.js
67 lines (51 loc) · 1.81 KB
/
script2.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function openPopup(popupId) {
var popup = document.getElementById(popupId);
closeAllPopups(); // Close all popups before opening a new one
popup.style.display = "block";
}
function closePopup(popupId) {
var popup = document.getElementById(popupId);
popup.style.display = "none";
}
function closeAllPopups() {
var popups = document.getElementsByClassName("popup");
for (var i = 0; i < popups.length; i++) {
popups[i].style.display = "none";
}
}
// Function to play a song
function playSong(source) {
const audioPlayer = document.getElementById('audioPlayer');
if (audioPlayer.src !== source) {
pauseSong();
audioPlayer.src = source;
}
audioPlayer.play();
}
// Function to pause the song
function pauseSong() {
const audioPlayer = document.getElementById('audioPlayer');
audioPlayer.pause();
}
// Function to initialize the music player
function initializePlayer() {
const songButtons = document.querySelectorAll('.songButton');
songButtons.forEach(function(button) {
button.setAttribute('data-playing', 'false');
button.addEventListener('click', function() {
const songSource = button.getAttribute('data-source');
const isPlaying = button.getAttribute('data-playing');
const playButton = document.getElementById('playButton1');
const popup = document.querySelector('.popup');
if (isPlaying === 'true') {
button.setAttribute('data-playing', 'false');
pauseSong();
} else {
button.setAttribute('data-playing', 'true');
playSong(songSource);
}
});
});
}
// Call the initializePlayer function when the page loads
window.addEventListener('load', initializePlayer);