-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
song7.js
208 lines (184 loc) · 7.33 KB
/
song7.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
console.log("Welcome to Spotify");
// Initialize the Variables
let songIndex = 0;
let audioElement = new Audio("song7/1.mp3");
let bottomPlay = document.getElementById('bottomPlay');
let bottomPlay1 = document.getElementById('bottomPlay1');
let progBar = document.getElementById('progBar');
let songPic = document.getElementById('songPic');
let ftrSongDisplayName = document.getElementById('ftrSongDisplayName');
let songItem = Array.from(document.getElementsByClassName('songItem'));
let timeStamp = document.getElementsByClassName("timeStamp").duration;
let track = document.getElementsByClassName('track')[0];
let circleontrack = document.getElementsByClassName('circleontrack')[0];
let dot = document.getElementsByClassName('dot')[0];
let songs = [
{ songName: "Desh Mere (Mohammad Rafi)", coverPath: "cover7/1.jpg"},
{ songName: "Gerua - Dilwale (Mohammad Rafi)", coverPath: "cover7/2.jpg"},
{ songName: "Janam Janam - Dilwale (Mohammad Rafi)", coverPath: "cover7/3.jpg"},
{ songName: "Kalank - Title Song(Mohammad Rafi)", coverPath: "cover7/4.jpg"},
{ songName: "Khairiyat Sad – Chhichhore(Mohammad Rafi)", coverPath: "cover7/5.jpg"},
{ songName: "Raabta - Title Song (Mohammad Rafi)", coverPath: "cover7/6.jpg"},
{ songName: "Phir Mohabbat - Murder 2(Mohammad Rafi)", coverPath: "cover7/7.jpg"},
{ songName: "Tera Yaar Hoon Main - Sonu Ke Titu Ki Sweety(Mohammad Rafi)", coverPath: "cover7/8.jpg"},
{ songName: "Tum Hi Ho - Aashiqui 2 (Mohammad Rafi)", coverPath: "cover7/9.jpg"},
{ songName: "Tum Saath Ho - Tamasha (Mohammad Rafi)", coverPath: "cover7/10.jpg"},
]
songItem.forEach((element, i) => {
element.getElementsByTagName("img")[0].src = songs[i].coverPath;
element.getElementsByClassName("songName")[0].innerText = songs[i].songName;
})
// Handle play/pause click
bottomPlay.addEventListener('click', () => {
if (audioElement.paused || audioElement.currentTime <= 0) {
audioElement.play();
bottomPlay.classList.remove('fa-play');
bottomPlay1.classList.remove('fa-play');
bottomPlay.classList.add('fa-pause');
bottomPlay1.classList.add('fa-pause');
songPic.style.opacity = 1;
}
else {
audioElement.pause();
bottomPlay.classList.remove('fa-pause');
bottomPlay1.classList.remove('fa-pause');
bottomPlay.classList.add('fa-play');
bottomPlay1.classList.add('fa-play');
songPic.style.opacity = 0;
}
})
// Listen to Events
let timeStart = document.getElementById('timeStart');
let timeEnd = document.getElementById('timeEnd');
audioElement.addEventListener('timeupdate', () => {
let music_curr = audioElement.currentTime;
let music_dur = audioElement.duration;
// update curr time
let min1 = Math.floor(music_curr / 60);
let sec1 = Math.floor(music_curr % 60);
if (sec1 < 10) {
sec1 = `0${sec1}`
}
timeStart.innerText = `${min1}:${sec1}`;
let min = Math.floor(music_dur / 60);
let sec = Math.floor(music_dur % 60);
if (sec < 10) {
sec = `0${sec}`
}
timeEnd.innerText = `${min}:${sec}`;
// Update Seekbar
progress = parseInt((audioElement.currentTime / audioElement.duration) * 100);
progBar.value = progress;
let seekBar = progBar.value;
track.style.width = `${seekBar}%`;
circleontrack.style.left = `${seekBar}%`;
})
progBar.addEventListener('change', () => {
audioElement.currentTime = progBar.value * audioElement.duration / 100;
})
const makeAllPlays = () => {
Array.from(document.getElementsByClassName('songItemPlay')).forEach((element) => {
element.classList.remove('fa-pause');
element.classList.add('fa-play');
})
}
Array.from(document.getElementsByClassName('songItemPlay')).forEach((element) => {
element.addEventListener('click', (e) => {
makeAllPlays();
songIndex = parseInt(e.target.id);
e.target.classList.remove('fa-play');
e.target.classList.add('fa-pause');
audioElement.src = `song7/${songIndex + 1}.mp3`;
songPic.src = `cover7/${songIndex + 1}.jpg`;
ftrSongDisplayName.innerText = songs[songIndex].songName;
audioElement.currentTime = 0;
audioElement.play();
songPic.style.opacity = 1;
bottomPlay.classList.remove('fa-play');
bottomPlay1.classList.remove('fa-play');
bottomPlay.classList.add('fa-pause');
bottomPlay1.classList.add('fa-pause');
})
})
// next button
document.getElementById('next').addEventListener('click', () => {
if (songIndex >= 9) {
songIndex = 0
}
else {
songIndex += 1;
}
audioElement.src = `song7/${songIndex + 1}.mp3`;
songPic.src = `cover7/${songIndex + 1}.jpg`;
ftrSongDisplayName.innerText = songs[songIndex].songName;
audioElement.currentTime = 0;
audioElement.play();
bottomPlay.classList.remove('fa-play');
bottomPlay1.classList.remove('fa-play');
bottomPlay.classList.add('fa-pause');
bottomPlay1.classList.add('fa-pause');
})
// previous button
document.getElementById('previous').addEventListener('click', () => {
if (songIndex <= 0) {
songIndex = 0;
}
else {
songIndex -= 1;
}
audioElement.src = `song7/${songIndex + 1}.mp3`;
songPic.src = `cover7/${songIndex + 1}.jpg`;
ftrSongDisplayName.innerText = songs[songIndex].songName;
audioElement.currentTime = 0;
audioElement.play();
bottomPlay.classList.remove('fa-play');
bottomPlay1.classList.remove('fa-play');
bottomPlay.classList.add('fa-pause');
bottomPlay1.classList.add('fa-pause');
})
let vol_icon = document.getElementById('vol_icon');
let volBar = document.getElementById('volBar');
let vol_dot = document.getElementById('vol_dot');
let vol_bar = document.getElementsByClassName('vol_bar')[0];
volBar.addEventListener('change', () => {
if (volBar.value == 100) {
vol_icon.classList.add('fa-volume-high');
vol_icon.classList.remove('fa-volume-xmark');
vol_icon.classList.remove('fa-volume');
vol_icon.classList.remove('fa-volume-low');
}
if (volBar.value == 0) {
vol_icon.classList.remove('fa-volume-high');
vol_icon.classList.add('fa-volume-xmark');
vol_icon.classList.remove('fa-volume');
vol_icon.classList.remove('fa-volume-low');
}
if (volBar.value > 0) {
vol_icon.classList.remove('fa-volume-high');
vol_icon.classList.remove('fa-volume-xmark');
vol_icon.classList.remove('fa-volume');
vol_icon.classList.add('fa-volume-low');
}
if (volBar.value > 25) {
vol_icon.classList.remove('fa-volume-high');
vol_icon.classList.remove('fa-volume-xmark');
vol_icon.classList.add('fa-volume');
vol_icon.classList.remove('fa-volume-low');
}
if (volBar.value > 55) {
vol_icon.classList.remove('fa-volume-high');
vol_icon.classList.remove('fa-volume-xmark');
vol_icon.classList.add('fa-volume');
vol_icon.classList.remove('fa-volume-low');
}
if (volBar.value > 50) {
vol_icon.classList.add('fa-volume-high');
vol_icon.classList.remove('fa-volume-xmark');
vol_icon.classList.remove('fa-volume');
vol_icon.classList.remove('fa-volume-low');
}
let vol_a = volBar.value;
vol_bar.style.width = `${vol_a}%`;
vol_dot.style.left = `${vol_a}%`;
audioElement.volume = vol_a / 100;
})