-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.html
More file actions
376 lines (324 loc) · 13.2 KB
/
Copy pathcontrol.html
File metadata and controls
376 lines (324 loc) · 13.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>音乐播放器 - 控制端</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f0f0f0;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.upload-section {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input[type="text"], input[type="file"] {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
button {
background-color: #007bff;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
margin-right: 10px;
}
button:hover {
background-color: #0056b3;
}
.playlists-section {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.playlist-item {
border: 1px solid #ddd;
padding: 10px;
margin-bottom: 10px;
border-radius: 4px;
}
.song-item {
padding: 5px 0;
border-bottom: 1px solid #eee;
}
.settings-section {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>音乐播放器 - 控制端</h1>
<!-- 音乐上传区域 -->
<div class="upload-section">
<h2>上传音乐</h2>
<form id="uploadForm">
<div class="form-group">
<label for="title">歌曲名称 *</label>
<input type="text" id="title" required>
</div>
<div class="form-group">
<label for="artist">歌手 *</label>
<input type="text" id="artist" required>
</div>
<div class="form-group">
<label for="album">所属专辑</label>
<input type="text" id="album">
</div>
<div class="form-group">
<label for="coverFile">封面文件 (可选)</label>
<input type="file" id="coverFile" accept="image/*">
</div>
<div class="form-group">
<label for="audioFile">音频文件 *</label>
<input type="file" id="audioFile" accept="audio/*" required>
</div>
<div class="form-group">
<label for="lyricsFile">歌词文件 (.lrc 或 .ttml)</label>
<input type="file" id="lyricsFile" accept=".lrc,.ttml">
</div>
<button type="submit">上传音乐</button>
</form>
</div>
<!-- 歌单管理区域 -->
<div class="playlists-section">
<h2>歌单管理</h2>
<div class="form-group">
<input type="text" id="playlistName" placeholder="输入新歌单名称">
<button onclick="createPlaylist()">创建歌单</button>
</div>
<div id="playlistsList"></div>
</div>
<!-- 播放设置区域 -->
<div class="settings-section">
<h2>播放设置</h2>
<div class="form-group">
<label>
<input type="checkbox" id="allowSkip" checked> 允许用户切歌
</label>
</div>
<div class="form-group">
<label>
<input type="checkbox" id="allowSeek" checked> 允许用户调整播放进度
</label>
</div>
<button onclick="updateSettings()">更新设置</button>
</div>
</div>
<script>
// 上传音乐
document.getElementById('uploadForm').addEventListener('submit', async function(e) {
e.preventDefault();
const title = document.getElementById('title').value;
const artist = document.getElementById('artist').value;
const album = document.getElementById('album').value;
const coverFile = document.getElementById('coverFile').files[0];
const audioFile = document.getElementById('audioFile').files[0];
const lyricsFile = document.getElementById('lyricsFile').files[0];
// 验证必要字段
if (!title || !artist || !audioFile) {
alert('音乐信息不全,无法上传');
return;
}
// 使用FormData上传文件
const formData = new FormData();
if (coverFile) formData.append('coverFile', coverFile);
if (audioFile) formData.append('audioFile', audioFile);
if (lyricsFile) formData.append('lyricsFile', lyricsFile);
try {
// 首先上传文件
const uploadResponse = await fetch('/upload', {
method: 'POST',
body: formData
});
const uploadResult = await uploadResponse.json();
if (!uploadResponse.ok) {
throw new Error(uploadResult.error || '上传失败');
}
// 获取上传后的文件信息
const coverFileName = uploadResult.files.coverFile ? uploadResult.files.coverFile.filename : '';
const audioFileName = uploadResult.files.audioFile ? uploadResult.files.audioFile.filename : '';
const lyricsFileName = uploadResult.files.lyricsFile ? uploadResult.files.lyricsFile.filename : '';
// 然后保存音乐信息
const musicData = {
title,
artist,
album,
coverFile: coverFileName,
audioFile: audioFileName,
lyricsFile: lyricsFileName
};
const response = await fetch('/api/music', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(musicData)
});
const result = await response.json();
if (response.ok) {
alert('音乐上传成功!');
document.getElementById('uploadForm').reset();
} else {
alert(result.error || '音乐保存失败');
}
} catch (error) {
console.error('Error:', error);
alert('上传过程中出现错误: ' + error.message);
}
});
// 创建歌单
async function createPlaylist() {
const name = document.getElementById('playlistName').value;
if (!name.trim()) {
alert('请输入歌单名称');
return;
}
try {
const response = await fetch('/api/playlist', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ name })
});
const result = await response.json();
if (response.ok) {
alert('歌单创建成功!');
document.getElementById('playlistName').value = '';
loadPlaylists();
} else {
alert(result.error || '创建歌单失败');
}
} catch (error) {
console.error('Error:', error);
alert('创建歌单时出现错误: ' + error.message);
}
}
// 加载并显示歌单
async function loadPlaylists() {
try {
const response = await fetch('/api/playlists');
const playlists = await response.json();
const playlistsContainer = document.getElementById('playlistsList');
playlistsContainer.innerHTML = '';
playlists.forEach(playlist => {
const playlistElement = document.createElement('div');
playlistElement.className = 'playlist-item';
playlistElement.innerHTML = `
<h3>${playlist.name}</h3>
<p>描述: ${playlist.description || '无描述'}</p>
<p>歌曲数量: ${playlist.songs.length}</p>
<button onclick="editPlaylist(${playlist.id})">编辑歌单</button>
<button onclick="deletePlaylist(${playlist.id})">删除歌单</button>
`;
playlistsContainer.appendChild(playlistElement);
});
} catch (error) {
console.error('Error loading playlists:', error);
}
}
// 编辑歌单
async function editPlaylist(id) {
// 这里可以实现更复杂的歌单编辑功能
const newName = prompt('请输入新的歌单名称:');
if (newName) {
try {
const response = await fetch(`/api/playlist/${id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ name: newName })
});
const result = await response.json();
if (response.ok) {
alert('歌单更新成功!');
loadPlaylists();
} else {
alert(result.error || '更新歌单失败');
}
} catch (error) {
console.error('Error:', error);
alert('更新歌单时出现错误: ' + error.message);
}
}
}
// 删除歌单
async function deletePlaylist(id) {
if (confirm('确定要删除这个歌单吗?')) {
try {
const response = await fetch(`/api/playlist/${id}`, {
method: 'DELETE'
});
const result = await response.json();
if (response.ok) {
alert('歌单删除成功!');
loadPlaylists();
} else {
alert(result.error || '删除歌单失败');
}
} catch (error) {
console.error('Error:', error);
alert('删除歌单时出现错误: ' + error.message);
}
}
}
// 更新播放设置
async function updateSettings() {
const allowSkip = document.getElementById('allowSkip').checked;
const allowSeek = document.getElementById('allowSeek').checked;
try {
const response = await fetch('/api/settings', {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ allowSkip, allowSeek })
});
const result = await response.json();
if (response.ok) {
alert('播放设置更新成功!');
} else {
alert(result.error || '更新设置失败');
}
} catch (error) {
console.error('Error:', error);
alert('更新设置时出现错误: ' + error.message);
}
}
// 页面加载时初始化
window.onload = function() {
loadPlaylists();
};
</script>
</body>
</html>