-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
133 lines (119 loc) · 4.57 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
console.log("welcome to spotify");
// import { readdirSync } from 'fs';
// var files = readdirSync('music/');
let songIndex=0;
let currentid=0;
let masterplay = document.getElementById('masterPlay');
let myProgressBar = document.getElementById('progressBar');
let songNameBottom=document.getElementById('songNameBottom');
console.log(songNameBottom);
let gif = document.getElementById('gif');
let audioElement = new Audio("music/1.mp3");
let songItems = Array.from(document.getElementsByClassName('songItem'));
let songs=[
{songName:"Memories - Maroon 5", filePath:"music/1.mp3",coverPath:"images/1.jpg"},
{songName:"I Believe In You - Michael Buble", filePath:"music/2.mp3",coverPath:"images/2.jpg"},
{songName:"Choo Lo - The Local Train", filePath:"music/3.mp3",coverPath:"images/3.jpg"},
{songName:"With Little Help - The Beatles", filePath:"music/4.mp3",coverPath:"images/4.jpg"},
{songName:"SOS - Avicii", filePath:"music/5.mp3",coverPath:"images/5.jpg"},
{songName:"Someone You Loved - Lewis Capaldi ", filePath:"music/6.mp3",coverPath:"images/6.jpg"},
{songName:"Boulevard of Broken Dreams", filePath:"music/7.mp3",coverPath:"images/7.jpg"},
{songName:"Honey And The Moon", filePath:"music/8.mp3",coverPath:"images/8.jpg"},
{songName:"Ishaaron Mein Girl in the city ", filePath:"music/9.mp3",coverPath:"images/9.jpg"},
{songName:"Queen - Crazy Little Thing Called Love", filePath:"music/10.mp3",coverPath:"images/10.jpg"},
];
songItems.forEach((element,i)=> {
console.log(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-play-circle');
masterplay.classList.add('fa-pause-circle');
gif.style.opacity=1;
}
else
{
audioElement.pause();
masterplay.classList.add('fa-play-circle');
masterplay.classList.remove('fa-pause-circle');
gif.style.opacity=0;
}
});
audioElement.addEventListener('timeupdate',()=>{
// console.log('timeupdated');
let progress = (audioElement.currentTime/audioElement.duration)*100;
myProgressBar.value = progress;
});
myProgressBar.addEventListener('change',()=>{
audioElement.currentTime=myProgressBar.value * audioElement.duration/100;
});
const makeAllPlays = ()=>{
Array.from(document.getElementsByClassName('songItemPlay')).forEach((element)=>{
element.classList.remove('fa-pause-circle');
element.classList.add('fa-play-circle');
});
};
Array.from(document.getElementsByClassName("songItemPlay")).forEach((element)=>{
element.addEventListener('click',(e)=>{
songIndex=parseInt(e.target.id);
if(audioElement.paused || audioElement.currentTime<=0 || currentid!=songIndex)
{
currentid = songIndex;
// console.log(e.target);
makeAllPlays();
gif.style.opacity=1;
songNameBottom.innerText = songs[songIndex].songName;
console.log(songs[songIndex].songName);
e.target.classList.remove('fa-play-circle');
e.target.classList.add('fa-pause-circle');
audioElement.src=`music/${songIndex + 1}.mp3`;
audioElement.currentTime=0;
audioElement.play();
masterplay.classList.remove('fa-play-circle');
masterplay.classList.add('fa-pause-circle');
}
else
{
audioElement.pause();
e.target.classList.remove('fa-pause-circle');
e.target.classList.add('fa-play-circle');
gif.style.opacity=0;
}
})
});
document.getElementById('next').addEventListener('click',()=>{
if(songIndex>=9)
{
songIndex=0;
}
else
{
songIndex+=1;
}
audioElement.src=`music/${songIndex + 1}.mp3`;
songNameBottom.innerText = songs[songIndex].songName;
audioElement.currentTime=0;
audioElement.play();
masterplay.classList.remove('fa-play-circle');
masterplay.classList.add('fa-pause-circle');
});
document.getElementById('previous').addEventListener('click',()=>{
if(songIndex<=0)
{
songIndex=9;
}
else
{
songIndex-=1;
}
audioElement.src=`music/${songIndex + 1}.mp3`;
songNameBottom.innerText = songs[songIndex].songName;
audioElement.currentTime=0;
audioElement.play();
masterplay.classList.remove('fa-play-circle');
masterplay.classList.add('fa-pause-circle');
});