-
Notifications
You must be signed in to change notification settings - Fork 14
/
061.音乐播放器.html
227 lines (194 loc) · 12.5 KB
/
061.音乐播放器.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./assets/global.css">
<style>
@keyframes rotate {
0% {
transform: rotate(0);
}
50% {
transform: rotate(180deg);
}
100% {
transform: rotate(360deg);
}
}
.music_player {
min-width: 54px;
height: 54px;
}
.music_player audio {
display: none;
}
.music_player__vinyl {
position: relative;
width: 120px;
height: 120px;
background-color: #f4f4f4;
}
.music_player__vinyl_cd {
position: absolute;
width: 100%;
height: 100%;
animation: 3s rotate linear infinite;
animation-play-state: paused;
}
.music_player__vinyl_cd.playing {
animation-play-state: running;
}
div[class*='music_player__vinyl_cd_q'] {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%)
}
.music_player__vinyl_cd_q1 {
width: 80%;
height: 80%;
background-color: #333;
border-radius: 50%;
}
div[class*='music_player__vinyl_cd_q1_'] {
border-radius: 50%;
border: 1px solid rgba(255, 255, 255, .05);
}
.music_player__vinyl_cd_q1_1 {
width: 45%;
height: 45%;
}
.music_player__vinyl_cd_q1_2 {
width: 50%;
height: 50%;
}
.music_player__vinyl_cd_q1_3 {
width: 55%;
height: 55%;
}
.music_player__vinyl_cd_q1_4 {
width: 60%;
height: 60%;
}
.music_player__vinyl_cd_q1_5 {
width: 65%;
height: 65%;
}
.music_player__vinyl_cd_q1_6 {
width: 70%;
height: 70%;
}
.music_player__vinyl_cd_q1_7 {
width: 75%;
height: 75%;
}
.music_player__vinyl_cd_q2 {
width: 40%;
height: 40%;
background-color: #888;
border-radius: 50%;
overflow: hidden;
}
.music_player__vinyl_cd_q2 img {
width: 100%;
height: 100%;
}
.music_player__vinyl_cd_q3 {
width: 10%;
height: 10%;
background-color: #f4f4f4;
border-radius: 50%;
}
.music_player__loading,
.music_player__play,
.music_player__pause {
position: absolute;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div class="music_player">
<audio controls>
<source src="./assets/musics/我会等-承桓.mp3" type="audio/mpeg">
</audio>
<div class="music_player__vinyl">
<div class="music_player__vinyl_cd">
<div class="music_player__vinyl_cd_q1"></div>
<div class="music_player__vinyl_cd_q1_1"></div>
<div class="music_player__vinyl_cd_q1_2"></div>
<div class="music_player__vinyl_cd_q1_3"></div>
<div class="music_player__vinyl_cd_q1_4"></div>
<div class="music_player__vinyl_cd_q1_5"></div>
<div class="music_player__vinyl_cd_q1_6"></div>
<div class="music_player__vinyl_cd_q1_7"></div>
<div class="music_player__vinyl_cd_q2">
<img src="./assets/musics/我会等-承桓.jpg">
</div>
<div class="music_player__vinyl_cd_q3"></div>
</div>
<div class="music_player__loading">
<!-- 加载中... -->
</div>
<div class="music_player__play">
<!-- 播放 -->
</div>
<div class="music_player__pause">
<!-- 暂停 -->
</div>
</div>
</div>
<script type="module">
/** @type {HTMLAudioElement}*/
let audioDom = document.querySelector('.music_player audio')
let loadingDom = document.querySelector('.music_player .music_player__loading')
let playDom = document.querySelector('.music_player .music_player__play')
let pauseDom = document.querySelector('.music_player .music_player__pause')
let musicPlayerDom = document.querySelector('.music_player .music_player__vinyl_cd')
pauseDom.hidden = true
playDom.hidden = true
/** 更新状态
* @param {"play"|'pause'|'loaded'|'ended'} status
*/
function updateStatus(status) {
switch (status) {
case "loaded":
loadingDom.hidden = true
playDom.hidden = false;
break;
case "pause":
case "ended":
playDom.hidden = false;
pauseDom.hidden = true
musicPlayerDom.classList.remove('playing')
break;
case "play":
pauseDom.hidden = false;
playDom.hidden = true
musicPlayerDom.classList.add('playing')
break;
default:
break;
}
}
audioDom.addEventListener("canplay", () => {
// 加载完成
updateStatus("loaded")
})
audioDom.addEventListener("ended", () => {
updateStatus("ended")
})
playDom.addEventListener("click", () => {
audioDom.play();
updateStatus("play")
})
pauseDom.addEventListener("click", () => {
audioDom.pause();
updateStatus("pause")
})
</script>
</body>
</html>