-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
156 lines (140 loc) · 6.01 KB
/
script.js
File metadata and controls
156 lines (140 loc) · 6.01 KB
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
// console.log('Welcome');
// //Innitialize the variables
// let songindex = 0;
// let audioElement = new Audio('1.mp3');
// let masterPlay = document.getElementById('masterPlay');
// let myProgressBar = document.getElementById('myProgressBar');
// let songs = [
// { songName: "Salam-e-Ishq", filePath: "song/1.mp3", coverPath: "covers/1.jpg" },
// { songName: "Salam-e-Ishq", filePath: "song/1.mp3", coverPath: "covers/1.jpg" },
// { songName: "Salam-e-Ishq", filePath: "song/1.mp3", coverPath: "covers/1.jpg" },
// { songName: "Salam-e-Ishq", filePath: "song/1.mp3", coverPath: "covers/1.jpg" },
// { songName: "Salam-e-Ishq", filePath: "song/1.mp3", coverPath: "covers/1.jpg" },
// { songName: "Salam-e-Ishq", filePath: "song/1.mp3", coverPath: "covers/1.jpg" },
// { songName: "Salam-e-Ishq", filePath: "song/1.mp3", coverPath: "covers/1.jpg" },
// { songName: "Salam-e-Ishq", filePath: "song/1.mp3", coverPath: "covers/1.jpg" },
// { songName: "Salam-e-Ishq", filePath: "song/1.mp3", coverPath: "covers/1.jpg" },
// { songName: "Salam-e-Ishq", filePath: "song/1.mp3", coverPath: "covers/1.jpg" }
// ]
// // Audio elment Play();
// // Handle play/pause click
// masterPlay.addEventListener('click',() =>{
// if(audioElement.paused || audioElement.currentTime <=0){
// audioElement.play();
// }
// });
// // Listen to Events
// myProgressBar.addEventListener('timeupdate',() => {
// console.log('timeupdate');
// // update seebar
// });
console.log("Welcome to Spotify")
let songindex = 0;
let audioElement = new Audio('./Songs/1.mp3');
let masterPlay = document.getElementById('masterPlay');
let Progressbar = document.getElementById('Progressbar');
let gif = document.getElementById('gif');
let masterSongName = document.getElementById('masterSongName');
let songItems = Array.from(document.getElementsByClassName('songItem'));
let Songs = [
{ songName: "Ban Ja Tu Meri Rani", filepath: "./Songs/1.mp3", coverPath: "./Cover/1.jpg" },
{ songName: "Janiye", filepath: "./Songs/2.mp3", coverPath: "./Cover/2.jpg" },
{ songName: "Nain ta Heere", filepath: "./Songs/3.mp3", coverPath: "./Cover/3.jpg" },
{ songName: "Hayye Oye", filepath: "./Songs/4.mp3", coverPath: "./Cover/4.jpg" },
{ songName: "Dheere Dheere", filepath: "./Songs/5.mp3", coverPath: "./Cover/5.jpg" },
{ songName: "Bekhayali", filepath: "./Songs/6.mp3", coverPath: "./Cover/6.jpg" },
{ songName: "Fakira By Sanam", filepath: "./Songs/7.mp3", coverPath: "./Cover/7.jpg" },
{ songName: "Jeene Laga Hu", filepath: "./Songs/8.mp3", coverPath: "./Cover/8.jpg" },
{ songName: "Zara Zara By Jalraj", filepath: "./Songs/9.m4a", coverPath: "./Cover/9.jpg" },
{ songName: "O Mere Sona re", filepath: "./Songs/10.mp3", coverPath: "./Cover/10.jpg" }
]
songItems.forEach((element, i) => {
element.getElementsByTagName("img")[0].src = Songs[i].coverPath;
element.getElementsByClassName("songName")[0].innerText = Songs[i].songName;
});
masterPlay.addEventListener('click', () => {
if (audioElement.paused || audioElement.currentTime <= 0) {
audioElement.play();
masterPlay.classList.remove('fa-circle-play');
masterPlay.classList.add('fa-circle-pause');
gif.style.opacity = 1;
}
else {
audioElement.pause();
masterPlay.classList.remove('fa-circle-pause');
masterPlay.classList.add('fa-circle-play');
gif.style.opacity = 0;
}
})
// Listen to Events
audioElement.addEventListener('timeupdate', () => {
// console.log('timeupdate');
Progress = parseInt((audioElement.currentTime / audioElement.duration) * 100);
// console.log(Progress);
Progressbar.value = Progress;
})
Progressbar.addEventListener('change', () => {
audioElement.currentTime = Progressbar.value * audioElement.duration / 100;
})
const makeAllPlays = () => {
Array.from(document.getElementsByClassName('songItemPlay')).forEach((element) => {
element.classList.add('fa-circle-play')
element.classList.remove('fa-circle-pause')
})
}
Array.from(document.getElementsByClassName('songItemPlay')).forEach((element) => {
element.addEventListener('click', (e) => {
if (e.target.classList.contains('fa-circle-play')) {
makeAllPlays();
songindex = parseInt(e.target.id);
e.target.classList.remove('fa-circle-play');
e.target.classList.add('fa-circle-pause');
audioElement.src = `./Songs/${songindex + 1}.mp3`;
masterSongName.innerText = Songs[songindex].songName;
audioElement.currentTime = 0;
audioElement.play();
gif.style.opacity = 1;
masterPlay.classList.remove('fa-circle-play');
masterPlay.classList.add('fa-circle-pause');
}
else {
e.target.classList.remove('fa-circle-pause');
e.target.classList.add('fa-circle-play');
audioElement.currentTime = 1;
audioElement.pause();
gif.style.opacity = 0;
masterPlay.classList.add('fa-circle-play');
masterPlay.classList.remove('fa-circle-pause');
}
});
});
document.getElementById('next').addEventListener('click', () => {
if (songindex >= 9) {
songindex = 0;
}
else {
songindex += 1;
}
audioElement.src = `./Songs/${songindex + 1}.mp3`;
masterSongName.innerText = Songs[songindex].songName;
audioElement.currentTime = 0;
audioElement.play();
gif.style.opacity = 1;
masterPlay.classList.add('fa-circle-play');
masterPlay.classList.remove('fa-circle-pause');
})
document.getElementById('previous').addEventListener('click', () => {
if (songindex <= 0) {
songindex = 0;
}
else {
songindex = 1;
}
audioElement.src = `./Songs/${songindex + 1}.mp3`;
masterSongName.innerText = Songs[songindex].songName;
audioElement.currentTime = 0;
audioElement.play();
gif.style.opacity = 1;
masterPlay.classList.add('fa-circle-play');
masterPlay.classList.remove('fa-circle-pause');
})