-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
286 lines (239 loc) · 10.2 KB
/
test.html
File metadata and controls
286 lines (239 loc) · 10.2 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<title>hi :3</title>
<style>
hr.solid {
border-top: 3px solid #bbb;
}
body {
background-image: url("./assets/img0.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100% 100%;
}
</style>
<link rel="stylesheet" href="css/7.css">
</head>
<body>
<div class="media-player">
<!-- music player by layercake.nekoweb.org and yumeoi.skin -->
<div class="main">
<style>
.music-player {
display: flex;
align-items: center;
}
.player-img {
width: 95px;
height: 95px;
border: var(--window-border) var(--window-border-color);
margin-right: 15px;
}
.player {
display: flex;
flex-direction: column;
align-items: start;
position: relative;
right: 10px;
}
#seekbar {
width: 169px;
position: relative;
right: 2px;
}
.controls {
display: flex;
align-items: center;
gap: 3px;
scale: 74%;
position: relative;
right: 29px;
}
.controls-img {
position: relative;
top: 1px;
height: 15px;
width: 15px;
cursor: pointer;
}
.time-display {
display: flex;
justify-content: space-between;
width: 169px;
font-size: 12px;
margin-top: 2px;
position: relative;
right: 2px;
left: 2px;
}
#song-select {
max-width: 169px;
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>
<div class="window glass active" style="max-width: 300px; height: 150px">
<div class="title-bar">
<div class="title-bar-text">Music Player</div>
<div class="title-bar-controls">
<button aria-label="Minimize"></button>
<button aria-label="Maximize"></button>
<button aria-label="Close"></button>
</div>
</div>
<div class="window-body has-space" style="display: flex; height: 100px">
<div class="music-player">
<img class="player-img" src="./assets/mediaicon.png" id="song-cover" alt="currently playing song album cover">
<div class="player">
<select id="song-select" onchange="changeTrack()" aria-label="song selection"></select>
<div class="time-display">
<span id="current-time">0:00</span>
<span id="total-time">0:00</span>
</div>
<input type="range" id="seekbar" min="0" value="0" step="1" onchange="seekTo()" aria-label="seek bar">
<div class="controls">
<button onclick="prevTrack()">
<img src="./assets/prev.png" class="controls-img" alt="previous song button">
</button>
<button onclick="playpauseTrack()">
<img id="play-pause-icon" src="./assets/play.png" class="controls-img" alt="pause and play button">
</button>
<button onclick="nextTrack()">
<img src="./assets/next.png" class="controls-img" alt="next song button">
</button>
</div>
</div>
<audio id="music-player"></audio>
</div>
</div>
</div>
<script>
let music = document.getElementById("music-player");
let musicSource = document.getElementById("music-source");
let playPauseIcon = document.getElementById("play-pause-icon");
let seekBar = document.getElementById("seekbar");
let songSelect = document.getElementById("song-select");
let songCover = document.getElementById("song-cover");
let songs = [
{
title: "ANTONYMPH - Vylet Pony",
file: "https://files.catbox.moe/crq66d.mp3",
image: "./assets/vylet.webp",
},
{
title: "Laputa - Panchiko",
file: "https://files.catbox.moe/w7694o.m4a",
image: "./assets/panchiko.webp",
},
{
title: "Rain World OST - Threat - Outskirts",
file: "https://files.catbox.moe/er5lal.mp3",
image: "./assets/rainworl.webp",
},
{
title: "Bloodhail - Have A Nice Life",
file: "https://files.catbox.moe/y90ltf.m4a",
image: "./assets/hanl.webp",
}
];
function shuffleSongs() {
songs.sort(() => Math.random() - 0.5);
}
function loadSongs() {
// shuffleSongs();
songSelect.innerHTML = "";
songs.forEach((song, index) => {
let option = document.createElement("option");
option.value = index;
option.textContent = song.title;
songSelect.appendChild(option);
});
songSelect.selectedIndex = 0;
changeTrack();
}
function formatTime(seconds) {
let minutes = Math.floor(seconds / 60);
let secs = Math.floor(seconds % 60);
if (secs < 10) secs = "0" + secs;
return minutes + ":" + secs;
}
function playpauseTrack() {
if (music.paused) {
music
.play()
.catch((error) => console.log("Failed:", error));
playPauseIcon.src = "./assets/pause.png";
} else {
music.pause();
playPauseIcon.src = "./assets/play.png";
}
}
function changeTrack(shouldPlay = true) {
let selectedIndex = songSelect.value;
let selectedSong = songs[selectedIndex];
if (selectedSong) {
music.pause();
music.src = selectedSong.file;
songCover.src = selectedSong.image;
music.load();
if (shouldPlay) {
music
.play()
.catch((error) => console.log("Playback Failed!", error));
playPauseIcon.src = "./assets/pause.png";
} else {
playPauseIcon.src = "./assets/play.png";
}
}
}
function prevTrack() {
let index = songSelect.selectedIndex;
if (index > 0) {
songSelect.selectedIndex = index - 1;
changeTrack(true);
}
}
function nextTrack() {
let index = songSelect.selectedIndex;
if (index < songSelect.options.length - 1) {
songSelect.selectedIndex = index + 1;
changeTrack(true);
}
}
music.addEventListener("loadedmetadata", function () {
if (!isNaN(music.duration)) {
seekBar.max = music.duration;
seekBar.value = 0;
document.getElementById("current-time").textContent = "0:00";
document.getElementById("total-time").textContent = formatTime(music.duration);
}
});
music.addEventListener("timeupdate", function () {
if (!isNaN(music.duration)) {
seekBar.max = music.duration;
let current = music.currentTime;
let duration = music.duration;
// update bar
seekBar.value = current;
// update times
document.getElementById("current-time").textContent = formatTime(current);
document.getElementById("total-time").textContent = formatTime(duration);
}
});
function seekTo() {
music.currentTime = Number(seekBar.value);
}
window.onload = function () {
loadSongs();
changeTrack(false);
};
</script>
</div>
</div>
</body>
</html>