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 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
| <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>网易云音乐播放器</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css"> <style> body { font-family: 'Helvetica Neue', Arial, sans-serif; margin: 0; padding: 0; display: flex; flex-direction: column; min-height: 100vh; background-color: #f5f5f5; } .container { max-width: 600px; margin: 20px auto; padding: 20px; background-color: #fff; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); } #player { position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000; } #player .aplayer { margin: 0; background-color: #252525; border-top: 1px solid #333; } #player .aplayer-info { padding: 7px 7px 0 10px; } #player .aplayer-lrc { margin-top: -15px; font-size: 16px; } #player .aplayer-lrc p { font-size: 16px; } #player .aplayer-lrc-contents { top: 5px; } #player .aplayer-list { background-color: #252525; border-top: 1px solid #333; max-height: 300px; overflow-y: auto; } #player .aplayer-list ol li { border-top: 1px solid #333; color: #fff; } #player .aplayer-list ol li:hover { background-color: #333; } #player .aplayer-list ol li.aplayer-list-light { background-color: #333; } #player .aplayer-list-author { color: #ddd; } .input-group { display: flex; margin-bottom: 20px; } #playlistUrl { flex-grow: 1; padding: 10px; border: 1px solid #ddd; border-radius: 4px 0 0 4px; } button { padding: 10px 20px; background-color: #1db954; color: white; border: none; border-radius: 0 4px 4px 0; cursor: pointer; } #togglePlaylist { position: fixed; bottom: 80px; right: 20px; z-index: 1001; width: 40px; height: 40px; background-color: rgba(29, 185, 84, 0.8); color: white; border: none; border-radius: 50%; cursor: pointer; font-size: 20px; display: flex; justify-content: center; align-items: center; transition: transform 0.3s ease; }
#togglePlaylist.rotated { transform: rotate(180deg); }
#player .aplayer-list.hidden { display: none; } .background-options { margin-top: 20px; } #customBackgroundUrl { width: 100%; padding: 5px; margin-top: 5px; }
#toggleInterface { position: fixed; top: 20px; right: 20px; z-index: 1001; padding: 10px; background-color: rgba(29, 185, 84, 0.8); color: white; border: none; border-radius: 4px; cursor: pointer; }
.container.hidden { display: none; } #toggleImmersive { position: fixed; top: 20px; left: 20px; z-index: 1001; padding: 10px; background-color: rgba(29, 185, 84, 0.8); color: white; border: none; border-radius: 4px; cursor: pointer; }
.immersive #player, .immersive #togglePlaylist, .immersive #toggleInterface, .immersive #interfaceContainer { display: none; }
.immersive #toggleImmersive { background-color: rgba(255, 0, 0, 0.8); } #player .aplayer-bar { margin-top: 5px; }
#player .aplayer-time { margin-top: 5px; }
#player .aplayer-controller { margin-top: -5px; }
#player .aplayer-volume-wrap { margin-top: -5px; }
#player .aplayer-icon-menu { display: none; }
#player .aplayer-music { margin-bottom: 5px; }
#player .aplayer-info { padding: 7px 7px 0 10px; }
#player .aplayer { padding-bottom: 5px; height: 75px; } </style> </head> <body> <button id="toggleImmersive" onclick="toggleImmersive()">沉浸模式</button> <button id="toggleInterface" onclick="toggleInterface()">隐藏界面</button> <div class="container" id="interfaceContainer"> <h1>网易云音乐播放器</h1> <div class="input-group"> <input type="text" id="playlistUrl" placeholder="输入网易云收藏音乐集ID"> <button onclick="loadPlaylist()">加载播放列表</button> </div> <div class="background-options"> <label> <input type="radio" name="backgroundType" value="bing" checked onchange="updateBackground()"> 必应每日图片 </label> <label> <input type="radio" name="backgroundType" value="custom" onchange="showCustomUrlInput()"> 自定义背景 </label> <div id="customUrlInputGroup" style="display: none;"> <input type="text" id="customBackgroundUrl" placeholder="输入自定义背景图片URL"> <button onclick="applyCustomBackground()">应用</button> </div> </div> <div id="debug"></div> </div> <button id="togglePlaylist" onclick="togglePlaylist()">▼</button> <div id="player"></div>
<script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script> <script> let ap = null; let isPlaylistVisible = true; let isInterfaceVisible = true; let isImmersive = false;
async function setBackground(imageUrl) { document.body.style.backgroundImage = `url('${imageUrl}')`; document.body.style.backgroundSize = 'cover'; document.body.style.backgroundPosition = 'center'; document.body.style.backgroundAttachment = 'fixed'; }
async function getBingDailyImage() { try { const response = await fetch('https://bing.biturl.top/'); const data = await response.json(); return data.url; } catch (error) { console.error('获取必应每日图片失败:', error); return null; } }
function showCustomUrlInput() { document.getElementById('customUrlInputGroup').style.display = 'block'; }
function hideCustomUrlInput() { document.getElementById('customUrlInputGroup').style.display = 'none'; }
function applyCustomBackground() { const customUrl = document.getElementById('customBackgroundUrl').value.trim(); if (customUrl) { setBackground(customUrl); } else { alert('请输入有效的背景图片URL'); } }
async function updateBackground() { const backgroundType = document.querySelector('input[name="backgroundType"]:checked').value; if (backgroundType === 'bing') { hideCustomUrlInput(); const bingImageUrl = await getBingDailyImage(); if (bingImageUrl) { setBackground(bingImageUrl); } else { alert('获取必应每日图片失败,请稍后再试'); } } else if (backgroundType === 'custom') { showCustomUrlInput(); } }
window.onload = updateBackground;
async function loadPlaylist() { const playlistId = document.getElementById('playlistUrl').value.trim(); const debugElement = document.getElementById('debug'); debugElement.innerHTML = '开始加载播放列表...';
if (!playlistId) { alert('请输入有效的播放列表ID'); return; }
try { debugElement.innerHTML += '<br>正在从API获取数据...'; const response = await fetch(`https://api.i-meto.com/meting/api?server=netease&type=playlist&id=${playlistId}`); if (!response.ok) { throw new Error('网络响应不正常: ' + response.status); } const data = await response.json(); debugElement.innerHTML += '<br>成功获取数据,长度: ' + data.length;
if (data && data.length > 0) { if (ap) { ap.destroy(); }
debugElement.innerHTML += '<br>正在初始化APlayer...'; ap = new APlayer({ container: document.getElementById('player'), mini: false, autoplay: false, theme: '#1db954', loop: 'all', order: 'list', preload: 'auto', volume: 0.7, mutex: true, lrcType: 3, listFolded: false, listMaxHeight: 300, audio: data }); debugElement.innerHTML += '<br>APlayer初始化完成'; } else { debugElement.innerHTML += '<br>未找到播放列表或播放列表为空'; alert('未找到播放列表或播放列表为空'); } } catch (error) { console.error('加载播放列表时出错:', error); debugElement.innerHTML += '<br>错误: ' + error.message; alert('加载播放列表失败,请检查网络连接或稍后重试'); } }
function togglePlaylist() { if (ap) { const playlistElement = document.querySelector('#player .aplayer-list'); const toggleButton = document.getElementById('togglePlaylist'); if (isPlaylistVisible) { playlistElement.classList.add('hidden'); toggleButton.classList.add('rotated'); } else { playlistElement.classList.remove('hidden'); toggleButton.classList.remove('rotated'); } isPlaylistVisible = !isPlaylistVisible; } }
function toggleInterface() { const container = document.getElementById('interfaceContainer'); const toggleButton = document.getElementById('toggleInterface'); if (isInterfaceVisible) { container.classList.add('hidden'); toggleButton.textContent = '显示界面'; } else { container.classList.remove('hidden'); toggleButton.textContent = '隐藏界面'; } isInterfaceVisible = !isInterfaceVisible; }
function toggleImmersive() { const body = document.body; const toggleButton = document.getElementById('toggleImmersive'); const interfaceContainer = document.getElementById('interfaceContainer'); if (isImmersive) { body.classList.remove('immersive'); toggleButton.textContent = '沉浸模式'; toggleButton.style.backgroundColor = 'rgba(29, 185, 84, 0.8)'; if (isInterfaceVisible) { interfaceContainer.classList.remove('hidden'); } } else { body.classList.add('immersive'); toggleButton.textContent = '退出沉浸'; toggleButton.style.backgroundColor = 'rgba(255, 0, 0, 0.8)'; interfaceContainer.classList.add('hidden'); } isImmersive = !isImmersive; }
document.addEventListener('keydown', function(event) { if (event.key === 'Escape') { if (isImmersive) { toggleImmersive(); } } }); </script> </body> </html>
|