-
Notifications
You must be signed in to change notification settings - Fork 22
/
script.js
172 lines (161 loc) · 4.64 KB
/
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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
const mainCard = document.querySelector("#ContentWarpper");
const songImg = document.querySelector("#SongImg");
const controlButtons = document.querySelector(".control");
const currentYear = new Date().getFullYear();
const playPauseButton = document.querySelector("#PausePlay");
const audio = document.querySelector("audio");
const artist = document.querySelector("#Artist");
const songName = document.querySelector("#SongName");
const previousButton = document.querySelector("#Previous");
const nextButton = document.querySelector("#Next");
const songImgAtTheTop = document.querySelector("img");
let startDuration = document.querySelector("#Start");
const endDuration = document.querySelector("#End");
const meter = document.querySelector("#ProgrssMeterChild");
const progressBar = document.querySelector("#ProgressMeterContainer");
let isPlaying = false;
let index = 0;
const songDataBase = [
{
songSrc: "./music/music1.mp3",
title: "Assalamu Alaika",
artist: "Maher Zain",
imgSrc: "./img/music1.jpg",
},
{
songSrc: "./music/music2.mp3",
title: "Deen Islam",
artist: "Mohamed Tarek",
imgSrc: "./img/music2.jpg",
},
{
songSrc: "./music/music3.mp3",
title: "Mix",
artist: "Mohammad Tarek",
imgSrc: "./img/music3.jpg",
},
{
songSrc: "./music/music4.mp3",
title: "Mohammad Nabina",
artist: "Unknown",
imgSrc: "./img/music4.jpg",
},
{
songSrc: "./music/music5.mp3",
title: "Asslamu Alaika",
artist: "Maher Zain",
imgSrc: "./img/music5.jpg",
},
{
songSrc: "./music/music6.mp3",
title: "Maulaya Salli",
artist: "Sami Yusuf",
imgSrc: "./img/music6.jpg",
},
{
songSrc: "./music/music7.mp3",
title: "Lakhon Salam",
artist: "Atif Aslam",
imgSrc: "./img/music7.jpg",
},
{
songSrc: "./music/music8.mp3",
title: "Assalamu Alaika",
artist: "Maher zain",
imgSrc: "./img/music1.jpg",
},
{
songSrc: "./music/music9.mp3",
title: "Maulaya Salli",
artist: "Mix",
imgSrc: "./img/music6.jpg",
},
{
songSrc: "./music/music10.mp3",
title: "Inshallah",
artist: "Maher Zain",
imgSrc: "./img/music10.jpg",
},
];
const loadMusic = () => {
audio.src = songDataBase[index].songSrc;
artist.textContent = songDataBase[index].artist;
songName.textContent = songDataBase[index].title;
songImgAtTheTop.src = songDataBase[index].imgSrc;
};
audio.addEventListener("ended", () => {
loadMusic(index++);
play();
});
loadMusic();
nextButton.addEventListener("click", () => {
if (index < songDataBase.length - 1) {
loadMusic(index++);
play();
} else {
pause();
}
});
previousButton.addEventListener("click", () => {
if (index > 0) {
loadMusic(index--);
play();
} else {
pause();
}
});
const play = () => {
isPlaying = true;
audio.play();
playPauseButton.classList.replace("fa-play", "fa-pause");
songImg.classList.add("anime");
};
const pause = () => {
isPlaying = false;
audio.pause();
playPauseButton.classList.replace("fa-pause", "fa-play");
songImg.classList.remove("anime");
};
playPauseButton.addEventListener("click", () => {
if (isPlaying) {
pause();
} else {
play();
}
});
let minute, second;
const timeStamp = (event) => {
let { duration, currentTime } = event.srcElement;
const full_second = Math.floor(duration % 60);
const full_minute = Math.floor(duration / 60);
const start_second = Math.floor(currentTime % 60);
const start_minute = Math.floor(currentTime / 60);
const totalDuration = `${full_minute} : ${full_second}`;
const currenDuration = `${start_minute} : ${start_second}`;
if (duration) {
endDuration.textContent = totalDuration;
}
startDuration.textContent = currenDuration;
const percentage = (currentTime / duration) * 100;
meter.style.width = `${percentage}%`;
};
audio.addEventListener("timeupdate", timeStamp);
progressBar.addEventListener("click", (event) => {
const { duration } = audio;
const moreProgress =
(event.offsetX / event.srcElement.clientWidth) * duration;
audio.currentTime = moreProgress;
});
document.querySelector("#Year").innerHTML = currentYear;
mainCard.addEventListener("mouseover", (event) => {
const xAxis = (window.innerWidth / 2 - event.pageX) / 15;
const yAxis = (window.innerHeight / 2 - event.pageY) / 15;
mainCard.style.transform = `rotateX(${yAxis}deg) rotateY(${xAxis}deg)`;
songImg.style.transform = `rotate(${xAxis}deg)`;
controlButtons.style.transform = `rotate(${xAxis}deg)`;
});
mainCard.addEventListener("mouseleave", () => {
mainCard.style.transform = "rotateX(0deg) rotateY(0deg)";
songImg.style.transform = "rotate(0deg)";
controlButtons.style.transform = "rotate(0deg)";
});