-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmusic_player.js
200 lines (183 loc) · 6.04 KB
/
music_player.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
const controli=document.getElementById("progress");
const song=document.getElementById("song");
const conti=document.getElementById("controlicon");
const pre=document.getElementById("preid");
const playpause=document.getElementById("playpauseid");
const next=document.getElementById("nextid");
const imageid=document.getElementById("img1");
const titleid=document.getElementById("titleid");
const singerid=document.getElementById("singerid");
const currenttime=document.getElementById("currenttime");
const totaltime=document.getElementById("totaltime");
const songlist=document.getElementById("songlist");
const songlistid=document.getElementById("songlistid");
i=0;
playpause.addEventListener("click",playpausefunction);
function playpausefunction()
{
if(conti.classList.contains('fa-circle-play'))
{ play(songdata[i]);
conti.classList.remove("fa-circle-play");
conti.classList.add("fa-circle-pause");
}
else {
pause();
conti.classList.remove('fa-circle-pause');
conti.classList.add('fa-circle-play');
}
}
function play(songdata)
{
document.getElementById("img1").classList.add("img2");
song.src=songdata.path;
imageid.src=songdata.image;
titleid.innerText=songdata.title;
singerid.innerText=songdata.singer;
song.play();
if(conti.classList.contains('fa-circle-play'))
{
id=setInterval(()=>{
progress.value=song.currentTime;
currenttime.innerText=`${Math.floor(progress.value/60)} . ${Math.floor(progress.value%60)}`;
},500)
}
}
function pause()
{
document.getElementById("img1").classList.remove("img2");
song.pause();
clearInterval(id);
}
next.addEventListener("click",()=>{
if(i==5){ i=-1;}
play(songdata[++i]);
if(conti.classList.contains('fa-circle-play'))
{
conti.classList.remove("fa-circle-play");
conti.classList.add("fa-circle-pause");
}
});
pre.addEventListener("click",()=>{
if(i==0){ i=6;}
play(songdata[--i]);
if(conti.classList.contains('fa-circle-play'))
{
conti.classList.remove("fa-circle-play");
conti.classList.add("fa-circle-pause");
}
});
song.onloadedmetadata = function(){
controli.max=song.duration;
controli.value=song.currentTime;
}
controli.onchange=function(){
play(songdata[i]);
document.getElementById("img1").classList.add("img2");
song.currentTime=controli.value;
conti.classList.remove("fa-circle-play");
conti.classList.add("fa-circle-pause");
}
function drawer(){
var elei=document.getElementById("toprighticon");
if(elei.classList.contains("fa-sun"))
{
// fa-solid fa-moon
elei.classList.remove("fa-sun");
elei.classList.add("fa-moon");
document.getElementById("containerid").style.backgroundColor='rgba(0,0,0,0)'
currenttime.style.color='rgb(0,0,0)';
// alert("new features comming soon ");
}
else {
elei.classList.remove("fa-moon");
elei.classList.add("fa-sun");
currenttime.style.color='rgb(255,255,255)';
document.getElementById("containerid").style.backgroundColor='rgba(12, 12, 12, 0.932)'
}
}
countof=0;
songlist.addEventListener("click",()=>{
if(countof%2==0)
{
songlistid.style.visibility = "visible";
document.getElementById('songarrow').classList.remove('fa-bars');
document.getElementById('songarrow').classList.add('fa-chevron-left');
// <i class="fa-solid fa-chevron-left"></i>
countof++;
}
else{
songlistid.style.visibility = "hidden";
document.getElementById('songarrow').classList.remove('fa-chevron-left');
document.getElementById('songarrow').classList.add('fa-bars');
countof++;
}
})
songdata=[
{path:'audio/song1.mp3',
image:'image/image1.jpg',
title:'Pehli Baarish Mein',
singer:"Jubin Nautiyal"},
{path:'audio/song2.mp3',
image:'image/image2.jpg',
title:"Tu Yaad aya ",
singer:"Adnan Sami"},
{path:'audio/song3.mp3',
image:'image/image3.jpg',
title:"Jeene Laga Hun",
singer:"Atif Aslam"},
{path:'audio/song4.mp3',
image:'image/image4.jpg',
title:"Tujh Mein Rab Dikhta",
singer:"Roop Kumar Rathod"},
{path:'audio/song5.mp3',
image:'image/image5.jpg',
title:"Falak Tak Chal Sath",
singer:"Udit Narayan"},
{path:'audio/song6.mp3',
image:'image/image6.jpg',
title:"Love me Like You Do",
singer:"Ellie Goulding"},
]
document.getElementById('song0').addEventListener("click",()=>
{play(songdata[0]);
songlistid.style.visibility = "hidden";
if(conti.classList.contains('fa-circle-play'))
{conti.classList.remove("fa-circle-play");
conti.classList.add("fa-circle-pause");}
countof++;}
);
document.getElementById('song1').addEventListener("click",()=>
{play(songdata[1]);
songlistid.style.visibility = "hidden";
if(conti.classList.contains('fa-circle-play'))
{conti.classList.remove("fa-circle-play");
conti.classList.add("fa-circle-pause");}
countof++;});
document.getElementById('song2').addEventListener("click",()=>
{play(songdata[2]);
songlistid.style.visibility = "hidden";
if(conti.classList.contains('fa-circle-play'))
{conti.classList.remove("fa-circle-play");
conti.classList.add("fa-circle-pause");}
countof++;});
document.getElementById('song3').addEventListener("click",()=>
{play(songdata[3]);
songlistid.style.visibility = "hidden";
if(conti.classList.contains('fa-circle-play'))
{conti.classList.remove("fa-circle-play");
conti.classList.add("fa-circle-pause");}
countof++;});
document.getElementById('song4').addEventListener("click",()=>
{play(songdata[4]);
songlistid.style.visibility = "hidden";
if(conti.classList.contains('fa-circle-play'))
{conti.classList.remove("fa-circle-play");
conti.classList.add("fa-circle-pause");}
countof++;});
document.getElementById('song5').addEventListener("click",()=>
{play(songdata[5]);
songlistid.style.visibility = "hidden";
if(conti.classList.contains('fa-circle-play'))
{conti.classList.remove("fa-circle-play");
conti.classList.add("fa-circle-pause");}
countof++;});