-
Notifications
You must be signed in to change notification settings - Fork 0
/
musicplayer(lite).html
301 lines (247 loc) · 10.8 KB
/
musicplayer(lite).html
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<!DOCTYPE html>
<html>
<style>
#musicplayer{
font-family:"MS UI Gothic", Tahoma; /* default font */
background:white; /* background color of player */
border:1px solid #202020; /* border around player */
width: 100%; /* width of the player - make it 100% if you want it to fill your container */
padding:0px;
text-align:center;
display:flex;
flex-direction:column;
gap:2px;
}
.songtitle, .track-info, .now-playing{
padding:2px;
}
.controls{
display:flex;
flex-direction:column;
gap:5px;
}
.buttons{
display:flex;
justify-content:center;
font-size:20px !important; /* size of controls */
width:100%;
}
.buttons div{
width:33.3%;
}
.playpause-track, .prev-track, .next-track{
color:#2b373f; /* color of buttons */
font-size:25px !important; /* size of buttons */
}
.volume-icon{
font-size:12px !important; /* size of volume icon */
}
.seeking, .volume{
display:flex;
flex-direction:row;
align-items:center;
gap:5px;
}
.now-playing, .track-info{
background-color:#cef2f5; /* background color of top two boxes */
}
.now-playing{
font-weight:bold;
}
input[type=range]{
-webkit-appearance:none; /* removes default appearance of the tracks */
width:100%;
}
input[type=range]:focus{
outline:none; /* removes outline around tracks when focusing */
}
input[type=range]::-webkit-slider-runnable-track{
width:100%;
height:2px; /* thickness of seeking track */
background:#2b373f; /* color of seeking track */
}
input[type=range]::-webkit-slider-thumb{
height:10px; /* height of seeking square */
width:10px; /* width of seeking square */
border-radius:0px; /* change to 5px if you want a circle seeker */
background:#2b373f; /* color of seeker square */
-webkit-appearance:none;
margin-top:-3px; /* fixes the weird margin around the seeker square in chrome */
}
input[type=range]::-moz-range-track{
width:100%;
height:4px; /* thickness of seeking track */
background:#2b373f; /* color of seeking track */
}
input[type=range]::-moz-range-thumb{
height:10px; /* height of seeking square */
width:10px; /* width of seeking square */
border-radius:0px; /* change to 5px if you want a circle seeker */
background:#2b373f; /* color of seeker square */
border:none; /* removes weird border around seeker square in firefox */
}
</style>
<body>
<div id="musicplayer">
<div class="now-playing"></div>
<div class="track-info">
<div class="track-name"></div>
<div class="track-artist"></div>
</div>
<div class="controls">
<div class="seeking">
<div class="current-time">00:00</div>
<input type="range" min="1" max="100" value="0" class="seek_slider" onchange="seekTo()">
<div class="total-duration">0:00</div>
</div>
<div class="buttons">
<div class="prev-track" onclick="prevTrack()">«</div>
<div class="playpause-track" onclick="playpauseTrack()">▶</div>
<div class="next-track" onclick="nextTrack()">»</div>
</div>
<div class="volume">
<div class="volume-icon">🕪</div>
<input type="range" min="1" max="100" value="25" class="volume_slider" onchange="setVolume()"> <!-- the default volume value is 25, change this if you want it to be higher or lower (i wouldn't recommend it bc it gets really loud) -->
</div>
</div>
<audio id="music" src=""></audio>
</div>
<script>
// initiate variables
let now_playing = document.querySelector(".now-playing");
let track_name = document.querySelector(".track-name");
let track_artist = document.querySelector(".track-artist");
let playpause_btn = document.querySelector(".playpause-track");
let next_btn = document.querySelector(".next-track");
let prev_btn = document.querySelector(".prev-track");
let seek_slider = document.querySelector(".seek_slider");
let volume_slider = document.querySelector(".volume_slider");
let curr_time = document.querySelector(".current-time");
let total_duration = document.querySelector(".total-duration");
let track_index = 0;
let isPlaying = false;
let updateTimer;
// create new audio element
let curr_track = document.getElementById("music");
//
// DEFINE YOUR SONGS HERE!!!!!
// MORE THAN FOUR SONGS CAN BE ADDED!!
// JUST ADD ANOTHER BRACKET WITH NAME ARTIST AND PATH
// CATBOX.MOE IS RECOMMENDED FOR UPLOADING MP3 FILES IF YOU DON'T HAVE NEOCITIES SUPPORTER
let track_list = [
{
name:"Lagtrain",
artist:"inabakumori",
path:"https://files.catbox.moe/9ywkki.mp3"
},
{
name:"Kimi ni Kaikisen",
artist:"inabakumori",
path:"https://files.catbox.moe/1pxdnw.mp3"
},
{
name:"God-ish",
artist:"Pinocchio-P",
path:"https://files.catbox.moe/xv3vdj.mp3"
},
{
name: "Her Boyfriend, Jude",
artist:"Syudou",
path: "https://files.catbox.moe/49iuxl.mp3",
},
];
//
//
//
//
//
function loadTrack(track_index){
clearInterval(updateTimer);
resetValues();
// load a new track
curr_track.src = track_list[track_index].path;
curr_track.load();
// update details of the track
track_name.textContent = track_list[track_index].name;
track_artist.textContent = track_list[track_index].artist;
now_playing.textContent = "Playing " + (track_index + 1) + " of " + track_list.length;
// set an interval of 1000 milliseconds for updating the seek slider
updateTimer = setInterval(seekUpdate, 1000);
// move to the next track if the current one finishes playing
curr_track.addEventListener("ended", nextTrack);
}
// reset values
function resetValues(){
curr_time.textContent = "0:00";
total_duration.textContent = "0:00";
seek_slider.value = 0;
}
// load the first track in the tracklist
loadTrack(track_index);
// checks if song is playing
function playpauseTrack(){
if (!isPlaying) playTrack();
else pauseTrack();
}
// plays track when play button is pressed
function playTrack(){
curr_track.play();
isPlaying = true;
// replace icon with the pause icon
playpause_btn.innerHTML = '▮';
}
// pauses track when pause button is pressed
function pauseTrack(){
curr_track.pause();
isPlaying = false;
playpause_btn.innerHTML = '▶';
}
// moves to the next track
function nextTrack(){
if (track_index < track_list.length - 1)
track_index += 1;
else track_index = 0;
loadTrack(track_index);
playTrack();
}
// moves to the previous track
function prevTrack(){
if (track_index > 0)
track_index -= 1;
else track_index = track_list.length;
loadTrack(track_index);
playTrack();
}
// seeker slider
function seekTo(){
seekto = curr_track.duration * (seek_slider.value / 100);
curr_track.currentTime = seekto;
}
// volume slider
function setVolume(){
curr_track.volume = volume_slider.value / 100;
}
setVolume();
function seekUpdate(){
let seekPosition = 0;
// check if the current track duration is a legible number
if (!isNaN(curr_track.duration)){
seekPosition = curr_track.currentTime * (100 / curr_track.duration);
seek_slider.value = seekPosition;
// calculate the time left and the total duration
let currentMinutes = Math.floor(curr_track.currentTime / 60);
let currentSeconds = Math.floor(curr_track.currentTime - currentMinutes * 60);
let durationMinutes = Math.floor(curr_track.duration / 60);
let durationSeconds = Math.floor(curr_track.duration - durationMinutes * 60);
// adding a zero to the single digit time values
if (currentSeconds < 10){ currentSeconds = "0" + currentSeconds; }
if (durationSeconds < 10){ durationSeconds = "0" + durationSeconds; }
if (currentMinutes < 10){ currentMinutes = currentMinutes; }
if (durationMinutes < 10){ durationMinutes = durationMinutes; }
curr_time.textContent = currentMinutes + ":" + currentSeconds;
total_duration.textContent = durationMinutes + ":" + durationSeconds;
}
}
</script>
</body>
</html>