starmusic-mobile
1<template>
2 <view :class="['play-detail', tvCls]" :style="themeStyle">
3 <tv-nav />
4 <!-- 动态毛玻璃背景:当前封面模糊 + 半透明遮罩 -->
5 <view class="bg-layer">
6 <image v-if="pic" class="bg-blur" :src="pic" mode="aspectFill" />
7 <view class="bg-overlay" />
8 </view>
9
10 <!-- 返回按钮(自定义导航栏,浮动在左上角) -->
11 <view class="nav-back tv-item d-press" data-navid="play-back" @click="handleBack">
12 <lx-icon name="close" :size="36" color="#606266" />
13 </view>
14
15 <!-- 歌曲信息 -->
16 <view class="music-header">
17 <image v-if="pic" class="music-pic pic-fade" :src="pic" mode="aspectFill" />
18 <view v-else class="music-pic placeholder">
19 <lx-icon name="music" :size="120" color="#c0c4cc" />
20 </view>
21 <text class="music-name">{{ currentMusic ? currentMusic.name : '未知歌曲' }}</text>
22 <text class="music-singer">{{ currentMusic ? currentMusic.singer : '未知歌手' }}</text>
23 </view>
24
25 <!-- 歌词 -->
26 <view class="lyric-area">
27 <scroll-view
28 scroll-y
29 class="lyric-scroll"
30 :scroll-top="lyricScrollTop"
31 scroll-with-animation
32 @scroll="handleLyricScroll"
33 >
34 <view class="lyric-content">
35 <view v-if="lyricLines.length" class="lyric-spacer" :style="{ height: lyricSpacerHeight }" />
36 <text
37 v-for="(line, index) in lyricLines"
38 :key="index"
39 :id="'lyric-line-' + index"
40 class="lyric-line"
41 :class="{ active: index === currentLyricIndex }"
42 >
43 {{ line.text || ' ' }}
44 </text>
45 <view v-if="lyricLines.length" class="lyric-spacer" :style="{ height: lyricSpacerHeight }" />
46 <text v-if="!lyricLines.length && lyricLoading" class="lyric-line lyric-empty">歌词加载中...</text>
47 <text
48 v-else-if="!lyricLines.length"
49 class="lyric-line lyric-empty"
50 @click="handleLyricRetry"
51 >
52 暂无歌词,点击重试
53 </text>
54 </view>
55 </scroll-view>
56 </view>
57
58 <!-- 主控制按钮:上一曲 / 播放 / 下一曲(一行对称) -->
59 <view class="controls-main">
60 <view class="ctrl-btn tv-item ctrl-prev d-press" data-navid="play-prev" @click="handlePrev">
61 <lx-icon name="prev" :size="56" color="#303133" />
62 </view>
63 <view class="ctrl-btn tv-item play-btn d-press" data-navid="play-toggle" :class="{ 'd-bounce': playBtnBounce }" @animationend="playBtnBounce = false" @click="handleTogglePlay">
64 <lx-icon :name="isPlay ? 'pause' : 'play'" :size="64" color="#fff" />
65 </view>
66 <view class="ctrl-btn tv-item ctrl-next d-press" data-navid="play-next" @click="handleNext">
67 <lx-icon name="next" :size="56" color="#303133" />
68 </view>
69 </view>
70
71 <!-- 次级控制按钮:模式 / 音质 / 收藏 / 下载 / 分享 -->
72 <view class="controls-sub">
73 <view class="ctrl-btn tv-item d-press" data-navid="play-mode" @click="handleToggleMethod">
74 <text class="ctrl-text mode-text">{{ modeText }}</text>
75 </view>
76 <view class="ctrl-btn tv-item d-press" data-navid="play-quality" @click="handleQualityTap">
77 <text class="ctrl-text quality-text">{{ getQualityText(currentQuality) }}</text>
78 </view>
79 <view class="ctrl-btn tv-item d-press" data-navid="play-collect" @click="handleCollect">
80 <lx-icon :name="isCollected ? 'heart-fill' : 'heart'" :size="48" :color="isCollected ? '#ff4d4f' : '#606266'" />
81 </view>
82 <view class="ctrl-btn tv-item d-press" data-navid="play-download" @click="handleDownload">
83 <lx-icon name="download" :size="48" color="#606266" />
84 </view>
85 <view class="ctrl-btn tv-item d-press" data-navid="play-share" @click="handleShare">
86 <lx-icon name="share" :size="48" color="#606266" />
87 </view>
88 </view>
89
90 <!-- 进度条(位于控制区下方) -->
91 <view class="progress-area">
92 <text class="time-text">{{ formatTime(currentTime) }}</text>
93 <slider
94 class="progress-slider"
95 :value="progressValue"
96 :max="duration > 0 ? Math.floor(duration) : 100"
97 :disabled="duration <= 0"
98 :activeColor="themeColor"
99 backgroundColor="rgba(0,0,0,0.1)"
100 :block-color="themeColor"
101 :block-size="16"
102 @changing="handleSeeking"
103 @change="handleSeek"
104 />
105 <text class="time-text">{{ formatTime(duration) }}</text>
106 </view>
107
108 <!-- 音质选择弹层 -->
109 <view v-if="showQualitySheet" class="quality-mask d-mask-in" @click="showQualitySheet = false">
110 <view class="quality-sheet d-slide-up" data-nav-scope @click.stop>
111 <view class="quality-sheet-title">选择音质</view>
112 <view
113 v-for="q in qualityList"
114 :key="q"
115 class="quality-item tv-item d-press"
116 data-navid="play-quality-option"
117 :class="{ active: q === currentQuality }"
118 @click="handleQualitySelect(q)"
119 >
120 <text class="quality-item-name">{{ getQualityText(q) }}</text>
121 <text v-if="q === currentQuality" class="quality-item-check">✓</text>
122 </view>
123 <view class="quality-item cancel tv-item d-press" data-navid="play-quality-cancel" @click="showQualitySheet = false">取消</view>
124 </view>
125 </view>
126
127 <!-- 下载音质选择弹层(独立于播放音质,下载时单独指定) -->
128 <view v-if="showDownloadSheet" class="quality-mask d-mask-in" @click="showDownloadSheet = false">
129 <view class="quality-sheet d-slide-up" data-nav-scope @click.stop>
130 <view class="quality-sheet-title">选择下载音质</view>
131 <view
132 v-for="q in downloadQualityList"
133 :key="q"
134 class="quality-item tv-item d-press"
135 data-navid="download-quality-option"
136 :class="{ active: q === downloadQuality }"
137 @click="handleDownloadQualitySelect(q)"
138 >
139 <text class="quality-item-name">{{ getQualityText(q) }}{{ getQualitySize(q) ? ' · ' + getQualitySize(q) : '' }}</text>
140 <text v-if="q === downloadQuality" class="quality-item-check">✓</text>
141 </view>
142 <view class="quality-item cancel tv-item d-press" data-navid="download-quality-cancel" @click="showDownloadSheet = false">取消</view>
143 </view>
144 </view>
145
146 <!-- 分享海报弹层:生成中 / 失败 / 预览保存 -->
147 <view v-if="showShareSheet" class="quality-mask d-mask-in" @click="closeShareSheet">
148 <view class="quality-sheet share-sheet d-slide-up" data-nav-scope @click.stop>
149 <view class="quality-sheet-title">分享这首歌</view>
150
151 <view v-if="shareState === 'preparing'" class="share-state">
152 <text class="share-state-text">正在生成分享海报…</text>
153 <text class="share-state-hint">解析播放地址 → 创建分享链接 → 绘制海报</text>
154 </view>
155
156 <view v-else-if="shareState === 'need-login'" class="share-state">
157 <text class="share-state-text">分享功能需要登录后使用</text>
158 <text class="share-state-hint">登录后即可生成分享海报,音乐资源由你的音源提供</text>
159 <view class="quality-item cancel tv-item d-press" data-navid="share-cancel" @click="closeShareSheet">知道了</view>
160 </view>
161
162 <view v-else-if="shareState === 'error'" class="share-state">
163 <text class="share-state-text is-error">{{ shareError }}</text>
164 <view class="quality-item tv-item d-press" data-navid="share-retry" @click="prepareShare">重试</view>
165 <view class="quality-item cancel tv-item d-press" data-navid="share-cancel" @click="closeShareSheet">取消</view>
166 </view>
167
168 <template v-else-if="shareState === 'ready'">
169 <image :src="sharePosterPath" class="share-poster" mode="aspectFit" />
170 <text class="share-state-hint">扫码即可在网页播放,链接有效期 30 天</text>
171 <view class="quality-item tv-item d-press" data-navid="share-save" @click="handleSavePoster">保存海报到相册</view>
172 <view class="quality-item tv-item d-press" data-navid="share-copy" @click="handleCopyShareLink">复制分享链接</view>
173 <view class="quality-item cancel tv-item d-press" data-navid="share-cancel" @click="closeShareSheet">关闭</view>
174 </template>
175 </view>
176 </view>
177
178 <!-- 分享海报离屏画布(经典 canvas,App/H5 全兼容;仅用于绘制,不参与布局) -->
179 <canvas canvas-id="sharePosterCanvas" id="sharePosterCanvas" class="share-canvas"></canvas>
180
181 <!-- 收藏到歌单弹层(可勾选多个歌单,点击即时生效) -->
182 <view v-if="showCollectSheet" class="quality-mask d-mask-in" @click="closeCollectSheet">
183 <view class="quality-sheet d-slide-up" data-nav-scope @click.stop>
184 <view class="quality-sheet-title">添加到歌单</view>
185 <view
186 v-for="item in collectLists"
187 :key="item.id"
188 class="quality-item tv-item d-press"
189 data-navid="collect-list-option"
190 :class="{ active: item.checked }"
191 @click="handleToggleCollectList(item)"
192 >
193 <text class="quality-item-name">{{ item.name }}</text>
194 <text v-if="item.checked" class="quality-item-check">✓</text>
195 </view>
196 <view class="quality-item tv-item d-press" data-navid="collect-create-list" @click="handleShowCreateList">+ 新建歌单</view>
197 <view class="quality-item cancel tv-item d-press" data-navid="collect-done" @click="closeCollectSheet">完成</view>
198 </view>
199 </view>
200
201 <!-- 新建歌单弹层(收藏弹层内进入) -->
202 <view v-if="showCreateList" class="quality-mask d-mask-in" @click="showCreateList = false">
203 <view class="quality-sheet d-slide-up" data-nav-scope @click.stop>
204 <view class="quality-sheet-title">新建歌单</view>
205 <view class="list-name-editor">
206 <input
207 v-model="newListName"
208 class="list-name-input"
209 placeholder="请输入歌单名称"
210 :maxlength="30"
211 confirm-type="done"
212 @confirm="handleCreateListConfirm"
213 />
214 </view>
215 <button class="list-name-btn" :disabled="!newListName.trim()" @click="handleCreateListConfirm">创建</button>
216 <view class="quality-item cancel tv-item d-press" data-navid="create-list-cancel" @click="showCreateList = false">取消</view>
217 </view>
218 </view>
219
220 <!-- 底部音频可视化(模拟频谱:canvas + 定时器驱动) -->
221 <view class="visualizer-area">
222 <canvas id="visualizer" canvas-id="visualizer" class="visualizer-canvas" />
223 </view>
224
225 <!-- 歌曲彩蛋层(纯观赏层,不拦截任何点击,8 秒后自动淡出) -->
226 <view v-if="easterEgg" class="easter-overlay">
227 <view class="easter-particles" :class="'easter-' + easterAnim">
228 <view
229 v-for="(p, index) in easterParticles"
230 :key="index"
231 class="easter-particle"
232 :style="{
233 left: p.left,
234 top: p.top,
235 animationDelay: p.delay,
236 animationDuration: p.duration,
237 }"
238 >
239 <text class="easter-particle-icon" :style="{ color: p.color, fontSize: p.size }">{{ p.icon }}</text>
240 </view>
241 </view>
242 <view class="easter-card d-pop-in">
243 <text class="easter-card-title">✦ {{ easterText }}</text>
244 <text class="easter-card-sub">星音乐 · 隐藏彩蛋</text>
245 </view>
246 </view>
247 </view>
248</template>
249
250<script>
251import * as player from '../../common/player.js'
252import event from '../../common/event.js'
253import { getSetting, updateSetting } from '../../common/setting.js'
254import { PLAY_MODE, QUALITYS } from '../../common/constants.js'
255import {
256 checkListContainsMusic,
257 addListMusics,
258 removeListMusics,
259 getCollectableLists,
260 createCustomList,
261 isMusicInAnyList,
262} from '../../common/playlist.js'
263import { getMusicUrl, getPicPath } from '../../common/music/index.js'
264import { createShare } from '../../common/share.js'
265import { drawSharePoster, posterToTempFile, downloadCover } from '../../common/poster.js'
266import { isLoggedIn, getLocalAccount } from '../../common/account.js'
267import { getLxGlobal } from '../../common/user-api/api-executor.js'
268import {
269 ensureEasterEggLoaded,
270 getLastTrigger,
271 buildSongKey,
272 getEggText,
273 getEggAnimation,
274} from '../../common/easter-egg.js'
275import LxIcon from '../../components/lx-icon/lx-icon.vue'
276import { deviceClass } from '../../common/tv.js'
277
278/** 音质显示名称 */
279const QUALITY_TEXT = {
280 flac24bit: 'Hi-Res',
281 flac: '无损',
282 wav: 'WAV',
283 ape: 'APE',
284 '320k': '320k',
285 '192k': '192k',
286 '128k': '128k',
287}
288
289export default {
290 components: { LxIcon },
291 data() {
292 return {
293 currentMusic: null,
294 pic: '',
295 isPlay: false,
296 currentTime: 0,
297 duration: 0,
298 progressValue: 0,
299 lyric: '',
300 lyricLines: [],
301 currentLyricIndex: -1,
302 lyricLoading: false,
303 // 歌词滚动位置(由代码计算,使当前行始终位于歌词区垂直中央)
304 lyricScrollTop: 0,
305 // 歌词上下留白高度(onReady 后按歌词区实际高度设置为 50%,保证首尾行也能居中)
306 lyricSpacerHeight: '30vh',
307 modeText: '列表循环',
308 isCollected: false,
309 seeking: false,
310 // 音质切换
311 currentQuality: '',
312 qualityList: [],
313 showQualitySheet: false,
314 qualitySwitching: false,
315 // 下载音质选择
316 showDownloadSheet: false,
317 downloadQuality: '',
318 downloadQualityList: [],
319 // 收藏到歌单
320 showCollectSheet: false,
321 collectLists: [],
322 showCreateList: false,
323 newListName: '',
324 // 分享海报
325 showShareSheet: false,
326 shareState: 'idle', // idle | need-login | preparing | ready | error
327 shareError: '',
328 sharePosterPath: '',
329 shareUrl: '',
330 // 播放键点击回弹动画
331 playBtnBounce: false,
332 // 底部音频可视化
333 visualizerW: 0,
334 visualizerH: 0,
335 visualizerBars: [],
336 visualizerInited: false,
337 // 下载完成后的保存路径(用于跳转文件管理器)
338 downloadedFilePath: '',
339 // 歌曲彩蛋
340 easterEgg: null,
341 easterAnim: 'fireworks',
342 easterParticles: [],
343 easterText: '',
344 // 遥控设备端 UI 类名
345 tvCls: '',
346 }
347 },
348 onLoad() {
349 this.tvCls = deviceClass()
350 // 自定义导航栏:App 端将状态栏文字设为黑色(页面为浅色毛玻璃背景)
351 // #ifdef APP-PLUS
352 try {
353 plus.navigator.setStatusBarStyle('dark')
354 } catch (e) {}
355 // #endif
356 const state = player.getPlayState()
357 this.currentMusic = state.playMusicInfo
358 this.isPlay = state.isPlay
359 this.currentTime = state.currentTime
360 this.duration = state.duration
361 this.pic = state.playMusicInfo ? state.playMusicInfo.img : ''
362 this.updateModeText()
363 this.updateCollectState()
364 this.updateQualityState()
365 this.bindEvents()
366
367 // 歌词在开始播放时就已获取并广播,本页此时尚未创建,
368 // 因此需要主动读取已留存的歌词;若为空则补偿请求一次。
369 // 延迟到首帧之后执行,避免进入页面瞬间触发歌词兜底链(含跨源搜索)抢占资源
370 const lyricInfo = state.lyricInfo
371 if (lyricInfo && lyricInfo.lyric) {
372 this.lyric = lyricInfo.lyric
373 this.parseLyric()
374 } else if (this.currentMusic) {
375 setTimeout(() => this.loadLyric(), 300)
376 }
377 },
378 onReady() {
379 // canvas 渲染完成后初始化可视化
380 this.initVisualizer()
381 // 依据歌词区实际高度计算上下留白(使当前行可居中显示)
382 this.initLyricSpacer()
383 // 页面完成首帧渲染后再触发彩蛋:
384 // 1) 避免彩蛋动画与页面初始渲染(毛玻璃封面 / 可视化 Canvas)抢资源导致短暂白屏
385 // 2) 保证用户能真正看到彩蛋,而不是在进入动画期间就已结束
386 setTimeout(() => this.checkEasterEgg(), 350)
387 },
388 onShow() {
389 // 从后台切回时重新获取尺寸并恢复动画
390 if (this.visualizerInited) this.initVisualizer()
391 // 歌词区高度可能已变化(如旋转屏幕),重新计算留白并定位
392 this.$nextTick(() => this.initLyricSpacer())
393 },
394 onResize() {
395 // 横竖屏切换后歌词区高度变化,需重算留白并重新定位当前行
396 this.$nextTick(() => this.initLyricSpacer())
397 },
398 onHide() {
399 this.stopVisualizer()
400 },
401 onUnload() {
402 this._destroyed = true
403 this.stopVisualizer()
404 this.clearEasterTimer()
405 this.unbindEvents()
406 },
407 onBackPress() {
408 // 遥控返回键优先关闭弹层,而不是直接退出播放页(后开起的弹层优先关闭)
409 if (this.showCreateList) {
410 this.showCreateList = false
411 return true
412 }
413 if (this.showCollectSheet) {
414 this.showCollectSheet = false
415 return true
416 }
417 if (this.showQualitySheet) {
418 this.showQualitySheet = false
419 return true
420 }
421 if (this.showDownloadSheet) {
422 this.showDownloadSheet = false
423 return true
424 }
425 if (this.showShareSheet) {
426 this.showShareSheet = false
427 return true
428 }
429 return false
430 },
431 methods: {
432 /** 返回上一页;若播放器页是首层页面(如从分享链接直接打开),回退到首页 Tab */
433 handleBack() {
434 const pages = getCurrentPages()
435 if (pages.length > 1) {
436 uni.navigateBack()
437 } else {
438 uni.reLaunch({ url: '/pages/index/index' })
439 }
440 },
441 bindEvents() {
442 this._offMusicInfo = event.on('playerMusicInfoChanged', (data) => {
443 this.currentMusic = data.musicInfo
444 // 切歌时关闭下载/收藏/分享弹层,避免操作目标与选择时不一致
445 this.showDownloadSheet = false
446 this.showCollectSheet = false
447 this.showCreateList = false
448 this.showShareSheet = false
449 this.updateCollectState()
450 this.updateQualityState()
451 // 切歌后重新计算该曲的 BPM 并重置节拍时钟
452 this.updateVisualizerBeat()
453 // 切歌后检测新歌曲彩蛋
454 this.checkEasterEgg()
455 })
456 this._offState = event.on('playerStateChanged', (data) => {
457 this.isPlay = data.isPlay
458 // 恢复播放时,若定时器已因完全透明而停止,则重启动画
459 if (data.isPlay && this.visualizerInited && !this._timer) this.restartVisualizer()
460 })
461 this._offProgress = event.on('playerProgressChanged', (data) => {
462 this.currentTime = data.currentTime
463 this.duration = data.duration
464 if (!this.seeking) this.progressValue = data.currentTime
465 this.updateLyricIndex()
466 })
467 this._offPic = event.on('playerPicUpdated', (url) => {
468 this.pic = url
469 })
470 this._offLyric = event.on('playerLyricUpdated', (lyricInfo) => {
471 const lyric = (lyricInfo && lyricInfo.lyric) || ''
472 // 本页正在补偿拉取时忽略空歌词广播,避免覆盖即将到来的结果
473 if (!lyric && this.lyricLoading) return
474 this.lyric = lyric
475 this.parseLyric()
476 })
477 this._offMethod = event.on('playMethodChanged', () => {
478 this.updateModeText()
479 })
480 },
481 unbindEvents() {
482 if (this._offMusicInfo) this._offMusicInfo()
483 if (this._offState) this._offState()
484 if (this._offProgress) this._offProgress()
485 if (this._offPic) this._offPic()
486 if (this._offLyric) this._offLyric()
487 if (this._offMethod) this._offMethod()
488 },
489 updateModeText() {
490 const mode = getSetting()['player.togglePlayMethod']
491 this.modeText = PLAY_MODE[mode] || '列表循环'
492 },
493 updateCollectState() {
494 if (!this.currentMusic) return
495 // 心形高亮表示已收藏到任意歌单(我的收藏或自定义歌单)
496 this.isCollected = isMusicInAnyList(this.currentMusic.id)
497 },
498 // ============ 分享海报 ============
499 /** 打开分享弹层并自动开始生成 */
500 handleShare() {
501 if (!this.currentMusic) {
502 uni.showToast({ title: '没有可分享的歌曲', icon: 'none' })
503 return
504 }
505 this.showShareSheet = true
506 this.prepareShare()
507 },
508 closeShareSheet() {
509 this.showShareSheet = false
510 },
511 /** 生成分享海报主流程:解析直链 → 创建短链 → 绘制海报 → 导出预览 */
512 async prepareShare() {
513 const info = this.currentMusic
514 if (!info) return
515 if (!isLoggedIn()) {
516 this.shareState = 'need-login'
517 return
518 }
519 this.shareState = 'preparing'
520 this.shareError = ''
521 try {
522 // 1. 用分享者自己的音源解析一条新鲜直链(isRefresh 绕过内存缓存)
523 const resolved = await getMusicUrl({ musicInfo: info, quality: this.currentQuality, isRefresh: true })
524 if (!resolved || !resolved.url) throw new Error('获取播放地址失败,无法分享')
525 // 2. 封面:先取地址,再下载临时文件(App 端原生通道;无封面不阻塞,海报走占位)
526 let coverUrl = this.pic || info.img || ''
527 try {
528 coverUrl = (await getPicPath({ musicInfo: info })) || coverUrl
529 } catch (e) {}
530 const coverPath = await downloadCover(coverUrl)
531 // 3. 创建云端分享
532 const res = await createShare({
533 musicInfo: info,
534 quality: resolved.quality || this.currentQuality,
535 playUrl: resolved.url,
536 coverUrl,
537 })
538 if (!res.shareUrl) throw new Error('分享服务返回异常')
539 this.shareUrl = res.shareUrl
540 // 4. 绘制海报(uni 经典 CanvasContext,App 端无 node.getContext)并导出预览
541 const sharer = (getLocalAccount() || {}).username || ''
542 const ctx = uni.createCanvasContext('sharePosterCanvas', this)
543 const ok = await drawSharePoster(ctx, {
544 name: info.name,
545 singer: info.singer,
546 album: info.albumName || info.album || '',
547 interval: info.interval || '',
548 quality: resolved.quality || this.currentQuality,
549 sharer,
550 coverPath,
551 shareUrl: res.shareUrl,
552 })
553 if (!ok) throw new Error('海报绘制失败')
554 this.sharePosterPath = await posterToTempFile('sharePosterCanvas', this)
555 this.shareState = 'ready'
556 } catch (err) {
557 console.log('[share]', err && err.message)
558 this.shareState = 'error'
559 this.shareError = (err && err.message) || '分享失败,请稍后重试'
560 }
561 },
562 /** 保存海报:App 端存相册(自动申请权限),H5 端浏览器下载 */
563 handleSavePoster() {
564 if (!this.sharePosterPath) return
565 // #ifdef APP-PLUS
566 plus.gallery.save(
567 this.sharePosterPath,
568 () => uni.showToast({ title: '海报已保存到相册', icon: 'none' }),
569 (e) => uni.showToast({ title: '保存失败:' + ((e && e.message) || '请检查相册权限'), icon: 'none' }),
570 )
571 // #endif
572 // #ifdef H5
573 const a = document.createElement('a')
574 a.href = this.sharePosterPath
575 a.download = `星音乐分享-${(this.currentMusic && this.currentMusic.name) || '海报'}.png`
576 document.body.appendChild(a)
577 a.click()
578 document.body.removeChild(a)
579 uni.showToast({ title: '海报已开始下载', icon: 'none' })
580 // #endif
581 },
582 /** 复制分享链接 */
583 handleCopyShareLink() {
584 if (!this.shareUrl) return
585 uni.setClipboardData({
586 data: this.shareUrl,
587 success: () => uni.showToast({ title: '链接已复制,去粘贴给朋友吧', icon: 'none' }),
588 })
589 },
590 // ============ 音质切换 ============
591 /** 音质显示名(无映射则显示原 key) */
592 getQualityText(q) {
593 return QUALITY_TEXT[q] || q || '标准'
594 },
595 /** 更新当前音质与可选音质列表 */
596 updateQualityState() {
597 const setting = getSetting()
598 this.currentQuality = setting['player.playQuality'] || '128k'
599 this.qualityList = this.getAvailableQualities()
600 },
601 /** 计算当前歌曲可选音质(按 QUALITYS 优先级排序) */
602 getAvailableQualities() {
603 const musicInfo = this.currentMusic
604 if (!musicInfo) return []
605 let list = []
606 // 1. 自定义源声明的音质(qualityList[source])
607 const lx = getLxGlobal()
608 const apiQualitys = lx.qualityList && lx.qualityList[musicInfo.source]
609 if (Array.isArray(apiQualitys) && apiQualitys.length) list = [...apiQualitys]
610 // 2. 内置源搜索返回的音质(_types 或 types)
611 if (!list.length && musicInfo._types) {
612 list = Object.keys(musicInfo._types)
613 }
614 if (!list.length && Array.isArray(musicInfo.types)) {
615 list = musicInfo.types.map((t) => t.type)
616 }
617 // 3. 兜底:全部音质
618 if (!list.length) list = [...QUALITYS]
619 // 按 QUALITYS 定义顺序排序(flac24bit 优先),去重
620 const orderMap = {}
621 QUALITYS.forEach((q, i) => (orderMap[q] = i))
622 return [...new Set(list)].sort((a, b) => {
623 const ia = orderMap[a] != null ? orderMap[a] : QUALITYS.length
624 const ib = orderMap[b] != null ? orderMap[b] : QUALITYS.length
625 return ia - ib
626 })
627 },
628 /** 打开音质选择弹层 */
629 handleQualityTap() {
630 if (!this.qualityList.length || this.qualitySwitching) return
631 this.updateQualityState()
632 this.showQualitySheet = true
633 },
634 /** 选择音质并切换 */
635 async handleQualitySelect(quality) {
636 if (this.qualitySwitching || quality === this.currentQuality) {
637 this.showQualitySheet = false
638 return
639 }
640 this.showQualitySheet = false
641 this.qualitySwitching = true
642 uni.showLoading({ title: '切换音质中...', mask: true })
643 try {
644 updateSetting({ 'player.playQuality': quality })
645 const ok = await player.refreshPlayUrl({ quality, isRefresh: true })
646 if (ok) {
647 this.currentQuality = quality
648 uni.showToast({ title: `已切换至${this.getQualityText(quality)}`, icon: 'none' })
649 }
650 } catch (err) {
651 uni.showToast({ title: (err && err.message) || '切换失败', icon: 'none' })
652 this.updateQualityState()
653 } finally {
654 uni.hideLoading()
655 this.qualitySwitching = false
656 }
657 },
658 /** 主动拉取歌词(进入页面时歌词为空,或用户点击重试) */
659 async loadLyric(isRefresh = false) {
660 if (this.lyricLoading) return
661 this.lyricLoading = true
662 try {
663 const lyricInfo = await player.refreshLyric(isRefresh)
664 this.lyric = (lyricInfo && lyricInfo.lyric) || ''
665 this.parseLyric()
666 } finally {
667 this.lyricLoading = false
668 }
669 },
670 /** 点击歌词区域重试获取 */
671 handleLyricRetry() {
672 if (this.lyricLines.length || this.lyricLoading) return
673 this.loadLyric(true)
674 },
675 parseLyric() {
676 this.lyricLines = []
677 this.lyricScrollTop = 0
678 this._lyricScrollTop = 0
679 if (!this.lyric) {
680 this.currentLyricIndex = -1
681 return
682 }
683 const lines = this.lyric.split(/\r\n|\r|\n/)
684 const timeExp = /\[(\d{1,2}):(\d{1,2})(?:[.:](\d{1,3}))?\]/g
685 for (const line of lines) {
686 let m
687 let lastTime = -1
688 const texts = []
689 while ((m = timeExp.exec(line)) !== null) {
690 const min = parseInt(m[1])
691 const sec = parseInt(m[2])
692 const msPart = m[3] ? parseInt(m[3]) : 0
693 const time = min * 60 + sec + (m[3] ? msPart / (m[3].length === 2 ? 100 : 1000) : 0)
694 if (lastTime < 0 || time > lastTime) lastTime = time
695 }
696 if (lastTime < 0) continue
697 const text = line.replace(/\[\d{1,2}:\d{1,2}(?:[.:]\d{1,3})?\]/g, '').trim()
698 this.lyricLines.push({ time: lastTime, text })
699 }
700 this.lyricLines.sort((a, b) => a.time - b.time)
701 this.updateLyricIndex()
702 },
703 updateLyricIndex() {
704 if (!this.lyricLines.length) {
705 this.currentLyricIndex = -1
706 return
707 }
708 let index = -1
709 for (let i = 0; i < this.lyricLines.length; i++) {
710 if (this.lyricLines[i].time <= this.currentTime + 0.3) {
711 index = i
712 } else {
713 break
714 }
715 }
716 if (index !== this.currentLyricIndex) {
717 this.currentLyricIndex = index
718 if (index >= 0) {
719 // 行切换后把当前行滚动到歌词区中央(等 DOM 更新出 active 类后再测量)
720 this.$nextTick(() => this.scrollToActiveLyric())
721 }
722 }
723 },
724 /** 记录歌词区当前滚动位置(计算居中目标时作为基准) */
725 handleLyricScroll(e) {
726 this._lyricScrollTop = e.detail.scrollTop
727 },
728 /** 把当前歌词行滚动到歌词区垂直中央 */
729 scrollToActiveLyric() {
730 if (this.currentLyricIndex < 0 || !this.lyricLines.length) return
731 const query = uni.createSelectorQuery().in(this)
732 query.select('.lyric-scroll').boundingClientRect()
733 query.select('.lyric-line.active').boundingClientRect()
734 query.exec((res) => {
735 const box = res && res[0]
736 const line = res && res[1]
737 if (!box || !line || !box.height || !line.height) return
738 // 当前行在滚动内容中的绝对位置 = 当前滚动值 + 行相对容器顶部的偏移
739 const offsetTop = (this._lyricScrollTop || 0) + (line.top - box.top)
740 // 目标:行中心与容器中心重合
741 const target = Math.max(0, Math.round(offsetTop - (box.height - line.height) / 2))
742 if (target === this.lyricScrollTop) return
743 this.lyricScrollTop = target
744 })
745 },
746 /**
747 * 依据歌词区实际高度设置上下留白(各占一半)
748 * 留白高度 + 计算出的 scrollTop 共同实现「当前行居中、上下各有若干行」的滚动歌词
749 */
750 initLyricSpacer() {
751 const query = uni.createSelectorQuery().in(this)
752 query.select('.lyric-scroll').boundingClientRect()
753 query.exec((res) => {
754 const box = res && res[0]
755 if (!box || !box.height) return
756 const half = Math.round(box.height / 2) + 'px'
757 if (this.lyricSpacerHeight !== half) this.lyricSpacerHeight = half
758 // 留白高度变化会改变内容总高度,稍后重新定位当前行
759 this.$nextTick(() => this.scrollToActiveLyric())
760 })
761 },
762 formatTime(time) {
763 if (!time || time < 0 || isNaN(time)) return '00:00'
764 const m = Math.floor(time / 60)
765 const s = Math.floor(time % 60)
766 return (m < 10 ? '0' + m : String(m)) + ':' + (s < 10 ? '0' + s : String(s))
767 },
768 handleSeeking(e) {
769 this.seeking = true
770 this.progressValue = e.detail.value
771 },
772 handleSeek(e) {
773 this.seeking = false
774 player.seek(e.detail.value)
775 },
776 handleTogglePlay() {
777 // 触发播放键弹性回弹动画(animationend 后复位)
778 this.playBtnBounce = false
779 this.$nextTick(() => {
780 this.playBtnBounce = true
781 })
782 player.togglePlay()
783 },
784 handlePrev() {
785 player.playPrev()
786 },
787 handleNext() {
788 player.playNext(false)
789 },
790 handleToggleMethod() {
791 player.togglePlayMethod()
792 },
793 /** 收藏:打开歌单选择弹层(可同时勾选多个歌单) */
794 handleCollect() {
795 if (!this.currentMusic) return
796 this.updateCollectSheet()
797 this.showCollectSheet = true
798 },
799 /** 刷新收藏弹层中各歌单的勾选状态 */
800 updateCollectSheet() {
801 if (!this.currentMusic) return
802 const musicId = this.currentMusic.id
803 this.collectLists = getCollectableLists().map((info) => ({
804 ...info,
805 checked: checkListContainsMusic(info.id, musicId),
806 }))
807 },
808 closeCollectSheet() {
809 this.showCollectSheet = false
810 },
811 /** 勾选 / 取消勾选某个歌单(点击即时生效) */
812 handleToggleCollectList(item) {
813 if (!this.currentMusic) return
814 const musicId = this.currentMusic.id
815 if (item.checked) {
816 removeListMusics(item.id, [musicId])
817 item.checked = false
818 uni.showToast({ title: `已从「${item.name}」移除`, icon: 'none' })
819 } else {
820 addListMusics(item.id, [this.currentMusic])
821 item.checked = true
822 uni.showToast({ title: `已添加到「${item.name}」`, icon: 'none' })
823 }
824 this.updateCollectState()
825 },
826 /** 打开新建歌单弹层(创建后自动收藏当前歌曲) */
827 handleShowCreateList() {
828 if (!this.currentMusic) return
829 this.newListName = ''
830 this.showCreateList = true
831 },
832 handleCreateListConfirm() {
833 const name = this.newListName.trim()
834 if (!name || !this.currentMusic) return
835 try {
836 const info = createCustomList(name)
837 addListMusics(info.id, [this.currentMusic])
838 this.showCreateList = false
839 this.newListName = ''
840 this.updateCollectSheet()
841 this.updateCollectState()
842 uni.showToast({ title: `已添加到「${info.name}」`, icon: 'none' })
843 } catch (err) {
844 uni.showToast({ title: err.message || '创建失败', icon: 'none' })
845 }
846 },
847 // ============ 底部音频可视化 ============
848 /**
849 * 初始化可视化:
850 * - 用 selectorQuery 读取 canvas 实际 px 尺寸(样式用 rpx,绘制必须用 px)
851 * - App 端 canvas 为原生组件,首次查询可能拿到 0 尺寸,失败则延迟重试
852 */
853 initVisualizer() {
854 if (this._destroyed) return
855 this.stopVisualizer()
856 const query = uni.createSelectorQuery().in(this)
857 query
858 .select('#visualizer')
859 .boundingClientRect((rect) => {
860 if (this._destroyed) return
861 if (!rect || !rect.width || !rect.height) {
862 setTimeout(() => this.initVisualizer(), 150)
863 return
864 }
865 this.visualizerW = rect.width
866 this.visualizerH = rect.height
867 if (!this.visualizerBars.length) this.initBars()
868 // 初始化节拍时钟(BPM 按当前歌曲计算)
869 this._beatPhase = 0
870 this._beatEnergy = 0
871 this.updateVisualizerBeat()
872 // 初始透明度:播放中直接显示,暂停中透明(随后由播放状态驱动淡入/淡出)
873 this._visualAlpha = this.isPlay ? 1 : 0
874 this.visualizerInited = true
875 // 旧手机性能优化:降频到 ~12fps(80ms),路径合并后视觉损失很小
876 this.restartVisualizer()
877 })
878 .exec()
879 },
880 initBars() {
881 // 柱间距按 21px/根 计算,数量约为之前的 2/3(barWidth 在 drawFrame 中按实际数量自适应撑宽)
882 const count = Math.max(12, Math.min(48, Math.floor(this.visualizerW / 21)))
883 this.visualizerBars = []
884 for (let i = 0; i < count; i++) {
885 this.visualizerBars.push({ value: 0, target: 0 })
886 }
887 },
888 stopVisualizer() {
889 if (this._timer) {
890 clearInterval(this._timer)
891 this._timer = null
892 }
893 },
894 /** 启动动画定时器(幂等;旧手机降频到 80ms/帧) */
895 restartVisualizer() {
896 if (this._timer) return
897 this._timer = setInterval(() => this.drawFrame(), 80)
898 },
899 /** 每帧:推进节拍时钟、更新柱高目标并绘制(BPM 节拍脉冲 + 频谱噪声) */
900 drawFrame() {
901 if (!this.visualizerW || !this.visualizerH || !this.visualizerBars.length) return
902 const bars = this.visualizerBars
903 const w = this.visualizerW
904 const h = this.visualizerH
905 const gap = 4
906 const barWidth = Math.max(2, (w - gap * (bars.length - 1)) / bars.length)
907 // context 复用,避免每帧创建开销
908 const ctx = this._ctx || (this._ctx = uni.createCanvasContext('visualizer', this))
909
910 // ---- 节拍时钟:按 BPM 计算拍间隔,每帧推进 phase,过一拍触发一次能量脉冲 ----
911 const dt = 0.08 // 帧间隔 80ms(与定时器保持一致)
912 const bpm = this._bpm || 120
913 const beatInterval = 60 / bpm // 一拍时长(秒)
914 if (this.isPlay) {
915 this._beatPhase += dt / beatInterval
916 if (this._beatPhase >= 1) {
917 this._beatPhase -= 1
918 this._beatEnergy = 1 // 节拍点:能量满格
919 }
920 // 拍点后按指数衰减,形成"冲高回落"的鼓点感
921 this._beatEnergy *= 0.82
922 } else {
923 this._beatEnergy = 0
924 }
925
926 // ---- 淡入淡出:播放时 5s 渐显,暂停时 5s 渐隐 ----
927 const fadeStep = dt / 5
928 const fadeTarget = this.isPlay ? 1 : 0
929 if (this._visualAlpha < fadeTarget) {
930 this._visualAlpha = Math.min(fadeTarget, this._visualAlpha + fadeStep)
931 } else if (this._visualAlpha > fadeTarget) {
932 this._visualAlpha = Math.max(fadeTarget, this._visualAlpha - fadeStep)
933 }
934 if (this._visualAlpha <= 0.01) {
935 // 完全透明:清空画布并停止定时器省 CPU(恢复播放时由 playerStateChanged 重启)
936 if (!this.isPlay) {
937 ctx.clearRect(0, 0, w, h)
938 ctx.draw()
939 this.stopVisualizer()
940 }
941 return
942 }
943
944 ctx.clearRect(0, 0, w, h)
945 ctx.setGlobalAlpha(this._visualAlpha)
946
947 // 底部淡色音轨(一次路径填充,避免逐柱状态切换)
948 ctx.setFillStyle(this.getThemeRgba(0.12))
949 ctx.beginPath()
950 for (let i = 0; i < bars.length; i++) {
951 ctx.rect(i * (barWidth + gap), h - 4, barWidth, 4)
952 }
953 ctx.fill()
954
955 // 跳动柱:高度 = 频谱噪声(各柱独立)+ 节拍脉冲(全体同步)。
956 // 所有柱子累积到同一路径后一次 fill,旧手机上可减少约一个数量级的 canvas 调用。
957 ctx.setFillStyle(this.getThemeRgba(0.65))
958 ctx.beginPath()
959 for (let i = 0; i < bars.length; i++) {
960 const b = bars[i]
961 if (this.isPlay) {
962 const noise = Math.random() // 频谱闪烁
963 const beatNoise = Math.random() // 节拍脉冲幅度
964 b.target = 0.12 + noise * 0.38 + this._beatEnergy * beatNoise * 0.55
965 if (b.target > 1) b.target = 1
966 } else {
967 b.target = 0
968 }
969 b.value += (b.target - b.value) * 0.35
970 if (b.value < 0.02) b.value = 0
971
972 const barH = b.value * h
973 if (barH < 2) continue
974 const x = i * (barWidth + gap)
975 // 纯矩形柱(省去圆头的 arc 路径构建)
976 ctx.rect(x, h - barH, barWidth, barH)
977 }
978 ctx.fill()
979
980 // 恢复全局透明度,避免影响下一帧 clearRect 之外的绘制
981 ctx.setGlobalAlpha(1)
982 ctx.draw()
983 },
984
985 /**
986 * 计算当前歌曲的 BPM 并重置节拍时钟。
987 * 元数据自带 bpm 字段则优先使用;否则按歌曲 id/名称生成稳定的伪随机 BPM(70~170),
988 * 保证同一首歌节奏恒定、切歌时跳动频率随之变化。
989 */
990 updateVisualizerBeat() {
991 this._bpm = this.getBpm(this.currentMusic)
992 this._beatPhase = 0
993 this._beatEnergy = 0
994 },
995 /**
996 * 打开下载音质选择弹层
997 * 下载音质独立于播放音质:由用户在弹层中显式指定,
998 * 并显式传给 getMusicUrl,避免走 getPlayQuality 的 _types 降级逻辑
999 */
1000 handleDownload() {
1001 if (!this.currentMusic) {
1002 uni.showToast({ title: '没有可下载的歌曲', icon: 'none' })
1003 return
1004 }
1005 const all = this.getAvailableQualities()
1006 if (!all.length) {
1007 uni.showToast({ title: '当前音源未声明可用音质', icon: 'none' })
1008 return
1009 }
1010 // 只列出有文件大小信息的档位;若全部档位都没有大小
1011 //(如自定义源搜索的歌不含 _types),则回退为全部档位,避免无档可选
1012 const withSize = all.filter((q) => !!this.getQualitySize(q))
1013 const list = withSize.length ? withSize : all
1014 this.downloadQualityList = list
1015 // 默认选中:上次下载音质 → 当前播放音质 → 最高可用档位
1016 const lastUsed = getSetting()['player.downloadQuality']
1017 const selected = list.includes(lastUsed)
1018 ? lastUsed
1019 : list.includes(this.currentQuality)
1020 ? this.currentQuality
1021 : list[0]
1022 this.downloadQuality = selected
1023 // 源只声明了一种音质时无需选择,直接下载
1024 if (list.length === 1) {
1025 this.startDownload(selected)
1026 return
1027 }
1028 this.showDownloadSheet = true
1029 },
1030 /** 选定下载音质后开始下载(记住本次选择) */
1031 handleDownloadQualitySelect(quality) {
1032 this.showDownloadSheet = false
1033 this.downloadQuality = quality
1034 updateSetting({ 'player.downloadQuality': quality })
1035 this.startDownload(quality)
1036 },
1037 /** 按指定音质获取下载地址并下载 */
1038 startDownload(quality) {
1039 const musicInfo = this.currentMusic
1040 uni.showLoading({ title: '正在获取下载地址...' })
1041 getMusicUrl({ musicInfo, quality, isRefresh: true })
1042 .then((info) => {
1043 uni.hideLoading()
1044 if (!info || !info.url) {
1045 uni.showToast({ title: '获取下载地址失败', icon: 'none' })
1046 return
1047 }
1048 // 以源实际返回的音质决定文件后缀
1049 const fileName = this.buildFileName(musicInfo, info.quality || quality)
1050 // #ifdef APP-PLUS
1051 // App 端统一走 uni.downloadFile 拿到临时文件,再按平台写入目标目录
1052 this.downloadWithUni(fileName, info.url)
1053 // #endif
1054 // #ifndef APP-PLUS
1055 uni.showLoading({ title: '下载中...' })
1056 uni.downloadFile({
1057 url: info.url,
1058 success: (res) => {
1059 uni.hideLoading()
1060 if (res.statusCode === 200 && res.tempFilePath) {
1061 uni.showToast({ title: '已保存到浏览器默认下载目录', icon: 'success', duration: 2000 })
1062 } else {
1063 uni.showToast({ title: '下载失败', icon: 'none' })
1064 }
1065 },
1066 fail: (err) => {
1067 uni.hideLoading()
1068 uni.showToast({ title: '下载失败:' + (err.errMsg || ''), icon: 'none' })
1069 },
1070 })
1071 // #endif
1072 })
1073 .catch((err) => {
1074 uni.hideLoading()
1075 uni.showToast({ title: '获取地址失败:' + (err.message || ''), icon: 'none' })
1076 })
1077 },
1078 /** 主题色的 rgba 字符串(canvas 不支持 CSS 变量,需按当前主题计算) */
1079 getThemeRgba(alpha) {
1080 const hex = this.themeColor || '#31c27c'
1081 const r = parseInt(hex.slice(1, 3), 16)
1082 const g = parseInt(hex.slice(3, 5), 16)
1083 const b = parseInt(hex.slice(5, 7), 16)
1084 return `rgba(${r}, ${g}, ${b}, ${alpha})`
1085 },
1086 /** 音质对应的参考大小(来自搜索/歌单信息,可能没有) */
1087 getQualitySize(quality) {
1088 const types = this.currentMusic && this.currentMusic._types
1089 return (types && types[quality] && types[quality].size) || ''
1090 },
1091 /**
1092 * 构造下载文件名
1093 * 歌曲名/歌手名常含 / : * ? " < > | 等字符,直接作为文件名会导致写入失败,
1094 * 统一替换为下划线,并限制长度避免超出文件系统上限;
1095 * 后缀按实际音质区分,避免无损文件被存成 .mp3。
1096 */
1097 buildFileName(musicInfo, quality) {
1098 const m = musicInfo || this.currentMusic || {}
1099 let base = (m.name || 'music').trim()
1100 if (m.singer) base += ' - ' + String(m.singer).trim()
1101 base = base.replace(/[\\/:*?"<>|\r\n]/g, '_').replace(/\s+/g, ' ')
1102 if (base.length > 80) base = base.slice(0, 80)
1103 return base + this.getQualityExt(quality)
1104 },
1105 /** 音质 → 文件后缀 */
1106 getQualityExt(quality) {
1107 switch (quality) {
1108 case 'flac':
1109 case 'flac24bit':
1110 return '.flac'
1111 case 'wav':
1112 return '.wav'
1113 case 'ape':
1114 return '.ape'
1115 default:
1116 return '.mp3'
1117 }
1118 },
1119 /** 下载到临时文件后再按平台写入目标目录 */
1120 downloadWithUni(fileName, url) {
1121 uni.showLoading({ title: '下载中...' })
1122 uni.downloadFile({
1123 url: url,
1124 success: (res) => {
1125 if (res.statusCode === 200 && res.tempFilePath) {
1126 this.saveDownloadFile(fileName, res.tempFilePath)
1127 } else {
1128 uni.hideLoading()
1129 uni.showToast({ title: '下载失败', icon: 'none' })
1130 }
1131 },
1132 fail: (err) => {
1133 uni.hideLoading()
1134 uni.showToast({ title: '下载失败:' + (err.errMsg || ''), icon: 'none' })
1135 },
1136 })
1137 },
1138 /**
1139 * 保存下载文件
1140 * App 端:优先保存到公共 Download 目录,失败则回退到应用私有 _downloads/
1141 * H5:downloadFile 已直接落在浏览器默认下载目录,仅提示
1142 */
1143 saveDownloadFile(fileName, tempFilePath) {
1144 // #ifdef APP-PLUS
1145 const sysInfo = uni.getSystemInfoSync()
1146 if (sysInfo.platform === 'android') {
1147 // Android:先用 MediaStore 写入公共 Download(分区存储唯一可靠方式),
1148 // 失败再退回直接路径写入(Android 9 及以下有效),最后退回应用私有目录
1149 const err = this.saveToPublicDownloadAndroid(fileName, tempFilePath)
1150 if (!err) {
1151 uni.hideLoading()
1152 this.showDownloadSuccess('已保存到 Download 文件夹')
1153 return
1154 }
1155 console.error('[download] 公共目录写入失败', err)
1156 }
1157 plus.io.resolveLocalFileSystemURL(tempFilePath, (tempEntry) => {
1158 this.saveToAppDownloads(fileName, tempEntry)
1159 }, () => {
1160 uni.hideLoading()
1161 uni.showToast({ title: '读取下载文件失败', icon: 'none' })
1162 })
1163 // #endif
1164 // #ifndef APP-PLUS
1165 uni.hideLoading()
1166 uni.showToast({ title: '已保存到浏览器默认下载目录', icon: 'success', duration: 2000 })
1167 // #endif
1168 },
1169 /**
1170 * Android:把临时文件写入公共 Download 目录(同步实现)
1171 * 返回 null 表示成功,返回错误信息字符串表示失败。
1172 *
1173 * 两条路径:
1174 * 1) Android 10+(API 29+):MediaStore.Downloads + ContentResolver.openOutputStream,
1175 * 这是分区存储下唯一不需要权限、且能写入公共目录的官方方式。
1176 * 2) Android 9 及以下:直接用 java.io 写文件路径,再触发媒体库扫描。
1177 *
1178 * 注意:plus.android 取得的运行时对象必须先 importClass(obj) 才能调用其方法。
1179 */
1180 saveToPublicDownloadAndroid(fileName, tempFilePath) {
1181 try {
1182 const main = plus.android.runtimeMainActivity()
1183 // 临时文件的真实绝对路径(tempFilePath 形如 _doc/uniapp_temp/... 或 file:///...)
1184 let srcPath = plus.io.convertLocalFileSystemURL(tempFilePath)
1185 if (srcPath.indexOf('file://') === 0) srcPath = srcPath.substring(7)
1186
1187 const Build = plus.android.importClass('android.os.Build$VERSION')
1188 const sdkInt = Build.SDK_INT
1189
1190 const FileInputStream = plus.android.importClass('java.io.FileInputStream')
1191 const input = new FileInputStream(srcPath)
1192 plus.android.importClass(input)
1193
1194 let output = null
1195 let targetPath = ''
1196
1197 if (sdkInt >= 29) {
1198 // ---- Android 10+:MediaStore 写入 ----
1199 const MediaStore = plus.android.importClass('android.provider.MediaStore')
1200 const ContentValues = plus.android.importClass('android.content.ContentValues')
1201 const values = new ContentValues()
1202 plus.android.importClass(values)
1203 values.put('_display_name', fileName)
1204 values.put('mime_type', 'audio/mpeg')
1205 values.put('relative_path', 'Download')
1206
1207 const resolver = main.getContentResolver()
1208 plus.android.importClass(resolver)
1209 const collection = MediaStore.Downloads.EXTERNAL_CONTENT_URI
1210 const itemUri = resolver.insert(collection, values)
1211 if (!itemUri) {
1212 input.close()
1213 return 'MediaStore insert 返回空'
1214 }
1215 output = resolver.openOutputStream(itemUri)
1216 targetPath = '/storage/emulated/0/Download/' + fileName
1217 } else {
1218 // ---- Android 9 及以下:直接写文件 ----
1219 const Environment = plus.android.importClass('android.os.Environment')
1220 const dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
1221 plus.android.importClass(dir)
1222 if (!dir.exists()) dir.mkdirs()
1223 targetPath = dir.getAbsolutePath() + '/' + fileName
1224 const FileOutputStream = plus.android.importClass('java.io.FileOutputStream')
1225 output = new FileOutputStream(targetPath)
1226 }
1227 plus.android.importClass(output)
1228
1229 if (sdkInt >= 29) {
1230 // Android 10+:用系统 FileUtils.copy 静态方法拷贝整个流,
1231 // 规避 plus.android 桥接 byte[] 数组不可靠导致写出 0 字节的问题
1232 const FileUtils = plus.android.importClass('android.os.FileUtils')
1233 const copied = FileUtils.copy(input, output)
1234 console.log('[download] 已拷贝字节数', String(copied))
1235 } else {
1236 // Android 9 及以下:手动分块拷贝
1237 const buf = plus.android.newObject('[B', 8192)
1238 let len = input.read(buf)
1239 while (len > 0) {
1240 output.write(buf, 0, len)
1241 len = input.read(buf)
1242 }
1243 }
1244 output.flush()
1245 output.close()
1246 input.close()
1247
1248 this.downloadedFilePath = targetPath
1249
1250 // Android 9 及以下需要主动通知媒体库,文件才会立刻出现在文件管理器
1251 if (sdkInt < 29) {
1252 try {
1253 const MediaScannerConnection = plus.android.importClass('android.media.MediaScannerConnection')
1254 MediaScannerConnection.scanFile(main, [targetPath], null, null)
1255 } catch (e) {}
1256 }
1257 return null
1258 } catch (e) {
1259 return (e && e.message) || String(e)
1260 }
1261 },
1262 /** 回退方案:保存到应用私有 _downloads/ 目录(无需任何权限) */
1263 saveToAppDownloads(fileName, tempEntry) {
1264 plus.io.resolveLocalFileSystemURL('_downloads/', (dirEntry) => {
1265 tempEntry.copyTo(dirEntry, fileName,
1266 () => {
1267 uni.hideLoading()
1268 this.downloadedFilePath = plus.io.convertLocalFileSystemURL('_downloads/' + fileName)
1269 this.showDownloadSuccess('已保存到应用下载目录')
1270 },
1271 () => {
1272 uni.hideLoading()
1273 uni.showToast({ title: '保存失败', icon: 'none' })
1274 }
1275 )
1276 }, () => {
1277 // _downloads/ 不存在,创建后再复制
1278 plus.io.requestFileSystem(plus.io.PRIVATE_DOC, (fs) => {
1279 fs.root.getDirectory('downloads', { create: true }, (dirEntry) => {
1280 tempEntry.copyTo(dirEntry, fileName,
1281 () => {
1282 uni.hideLoading()
1283 this.downloadedFilePath = plus.io.convertLocalFileSystemURL('_downloads/' + fileName)
1284 this.showDownloadSuccess('已保存到应用下载目录')
1285 },
1286 () => {
1287 uni.hideLoading()
1288 uni.showToast({ title: '保存失败', icon: 'none' })
1289 }
1290 )
1291 }, () => {
1292 uni.hideLoading()
1293 uni.showToast({ title: '保存失败', icon: 'none' })
1294 })
1295 }, () => {
1296 uni.hideLoading()
1297 uni.showToast({ title: '保存失败', icon: 'none' })
1298 })
1299 })
1300 },
1301 /** 下载成功后弹出带"查看文件"按钮的提示 */
1302 showDownloadSuccess(msg) {
1303 uni.showModal({
1304 title: '下载完成',
1305 content: msg,
1306 confirmText: '查看文件',
1307 cancelText: '关闭',
1308 success: (res) => {
1309 if (res.confirm) this.openFileManager()
1310 },
1311 })
1312 },
1313 /**
1314 * 调起系统文件管理器定位到下载文件
1315 * Android:依次尝试
1316 * 1) 系统文件管理器(DocumentsUI)打开公共 Download 目录 —— 覆盖 AOSP/多数 ROM
1317 * 2) 第三方文件管理器常见 Intent
1318 * 3) 打开文件本身(系统播放器/文件应用处理)
1319 */
1320 openFileManager() {
1321 // #ifdef APP-PLUS
1322 const main = plus.android.runtimeMainActivity()
1323 const Intent = plus.android.importClass('android.content.Intent')
1324 const Uri = plus.android.importClass('android.net.Uri')
1325
1326 // 尝试1:系统文件管理器(DocumentsUI)打开公共 Download 目录
1327 try {
1328 const intent = new Intent(Intent.ACTION_VIEW)
1329 intent.setData(Uri.parse('content://com.android.externalstorage.documents/document/primary%3ADownload'))
1330 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
1331 main.startActivity(intent)
1332 return
1333 } catch (e) {}
1334
1335 // 尝试2:file:// 目录 URI(部分 ROM/第三方文件管理器支持)
1336 try {
1337 const intent = new Intent(Intent.ACTION_VIEW)
1338 intent.setDataAndType(Uri.parse('file:///storage/emulated/0/Download'), 'resource/folder')
1339 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
1340 main.startActivity(intent)
1341 return
1342 } catch (e) {}
1343
1344 // 尝试3:打开具体文件(系统会弹出播放器或文件管理器选择)
1345 if (this.downloadedFilePath) {
1346 let path = this.downloadedFilePath
1347 if (path.indexOf('file://') === 0) path = path.replace('file://', '')
1348 try {
1349 const File = plus.android.importClass('java.io.File')
1350 const file = new File(path)
1351 if (file.exists()) {
1352 const intent = new Intent(Intent.ACTION_VIEW)
1353 intent.setDataAndType(Uri.fromFile(file), 'audio/mpeg')
1354 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
1355 main.startActivity(intent)
1356 return
1357 }
1358 } catch (e) {}
1359 }
1360
1361 uni.showToast({
1362 title: '请打开系统"文件"应用或通知栏查看下载',
1363 icon: 'none',
1364 duration: 2500,
1365 })
1366 // #endif
1367 },
1368 getBpm(musicInfo) {
1369 if (!musicInfo) return 120
1370 const meta = musicInfo.meta || {}
1371 if (meta.bpm && meta.bpm > 0) return meta.bpm
1372 const key = (musicInfo.id || '') + '|' + (musicInfo.name || '') + '|' + (musicInfo.singer || '')
1373 let hash = 0
1374 for (let i = 0; i < key.length; i++) {
1375 hash = (hash * 31 + key.charCodeAt(i)) | 0
1376 }
1377 return 70 + (Math.abs(hash) % 101) // 70~170
1378 },
1379 // ============ 歌曲彩蛋 ============
1380 /**
1381 * 检测并触发当前歌曲的彩蛋(进入播放页 / 切歌时调用)
1382 * - 若该歌曲在进入本页前已触发过彩蛋(如上次播放),直接恢复展示,不重复震动
1383 * - 否则触发新彩蛋(会话内同一首歌只触发一次)
1384 * - 彩蛋配置未就绪时先补拉一次,避免启动拉取较慢导致配置不生效
1385 */
1386 async checkEasterEgg() {
1387 const music = this.currentMusic
1388 if (!music) return
1389 const last = getLastTrigger()
1390 if (last && last.songKey === buildSongKey(music)) {
1391 // 1 分钟内触发的彩蛋,进入页面时恢复展示(不重复震动)
1392 if (Date.now() - last.time < 60000) this.showEasterEgg(last.egg)
1393 return
1394 }
1395 const egg = await ensureEasterEggLoaded(music)
1396 if (!egg) return
1397 // 异步等待期间可能已切歌或页面已卸载,需校验目标歌曲未变
1398 if (this._destroyed || !this.currentMusic || buildSongKey(this.currentMusic) !== buildSongKey(music)) return
1399 this.showEasterEgg(egg)
1400 },
1401 /** 展示彩蛋(动画 + 文案),8 秒后自动淡出 */
1402 showEasterEgg(egg) {
1403 if (!egg) return
1404 this.easterEgg = egg
1405 // 动画类型在 JS 侧解析后存入 data,模板只读字段(模板不能调用 import 的函数)
1406 this.easterAnim = getEggAnimation(egg)
1407 this.easterParticles = this.buildParticles(this.easterAnim)
1408 this.easterText = getEggText(egg)
1409 this.clearEasterTimer()
1410 this._easterTimer = setTimeout(() => this.closeEasterEgg(), 8000)
1411 },
1412 closeEasterEgg() {
1413 this.clearEasterTimer()
1414 this.easterEgg = null
1415 this.easterParticles = []
1416 },
1417 clearEasterTimer() {
1418 if (this._easterTimer) {
1419 clearTimeout(this._easterTimer)
1420 this._easterTimer = null
1421 }
1422 },
1423 /**
1424 * 按动画类型生成粒子配置(图标 / 颜色 / 位置 / 延迟 / 时长)
1425 * 每种动画对应一套 CSS keyframes,粒子样式差异(起始位置/速度)由内联样式驱动。
1426 */
1427 buildParticles(animation) {
1428 const rnd = (min, max) => min + Math.random() * (max - min)
1429 // 全部使用单色文本符号(不用彩色 emoji):老设备 emoji 字体加载慢且部分符号缺字形,
1430 // 颜色由内联 color 提供,渲染开销更稳定
1431 const iconSets = {
1432 fireworks: ['✦', '✧', '★', '✶', '✷', '●'],
1433 hearts: ['♥', '♡', '❥'],
1434 notes: ['♪', '♫', '♬', '♩'],
1435 sparkle: ['✦', '✧', '✩', '✶'],
1436 meteor: ['✧', '✦', '•'],
1437 }
1438 const palettes = {
1439 fireworks: ['#ff6b6b', '#feca57', '#48dbfb', '#ff9ff3', '#5f27cd', 'var(--theme-color, #31c27c)'],
1440 hearts: ['#ff6b81', '#ff9ff3', '#ffd3e0'],
1441 notes: ['var(--theme-color, #31c27c)', '#54a0ff', '#5f27cd'],
1442 sparkle: ['#ffd166', '#f9f871', '#ff9ff3'],
1443 meteor: ['#ffd166', '#ff9f43', '#ff6b6b'],
1444 }
1445 const icons = iconSets[animation] || iconSets.fireworks
1446 const palette = palettes[animation] || palettes.fireworks
1447 const isSparkle = animation === 'sparkle'
1448 const isMeteor = animation === 'meteor'
1449 // 控制粒子数量:过多动画粒子会在低端设备上与页面首帧渲染抢资源
1450 const count = animation === 'fireworks' ? 12 : 10
1451 const list = []
1452 for (let i = 0; i < count; i++) {
1453 list.push({
1454 icon: icons[Math.floor(Math.random() * icons.length)],
1455 color: palette[Math.floor(Math.random() * palette.length)],
1456 size: Math.round(rnd(24, 44)) + 'rpx',
1457 left: (isMeteor ? rnd(55, 98) : rnd(2, 98)).toFixed(1) + '%',
1458 top: isSparkle ? rnd(5, 90).toFixed(1) + '%' : '',
1459 delay: rnd(0, 0.9).toFixed(2) + 's',
1460 duration: (isSparkle ? rnd(1.4, 2.2) : rnd(2.2, 3.6)).toFixed(2) + 's',
1461 })
1462 }
1463 return list
1464 },
1465 },
1466}
1467</script>
1468
1469<style lang="scss" scoped>
1470.play-detail {
1471 display: flex;
1472 flex-direction: column;
1473 height: 100vh;
1474 position: relative;
1475 overflow: hidden;
1476 background: #f5f6f8;
1477}
1478
1479/* ---- 动态毛玻璃背景 ---- */
1480.bg-layer {
1481 position: absolute;
1482 top: 0;
1483 left: 0;
1484 right: 0;
1485 bottom: 0;
1486 z-index: 0;
1487 overflow: hidden;
1488}
1489
1490.bg-blur {
1491 position: absolute;
1492 top: -60rpx;
1493 left: -60rpx;
1494 width: 120%;
1495 height: 120%;
1496 /* H5 端模糊;App 端 filter 不生效但放大+遮罩仍可用 */
1497 filter: blur(60px);
1498 transform: scale(1.2);
1499}
1500
1501.bg-overlay {
1502 position: absolute;
1503 top: 0;
1504 left: 0;
1505 right: 0;
1506 bottom: 0;
1507 background: rgba(255, 255, 255, 0.55);
1508}
1509
1510/* ---- 返回按钮(自定义导航栏) ---- */
1511.nav-back {
1512 position: fixed;
1513 top: calc(var(--status-bar-height, 0px) + 20rpx);
1514 left: 24rpx;
1515 z-index: 10;
1516 width: 72rpx;
1517 height: 72rpx;
1518 border-radius: 36rpx;
1519 background: rgba(255, 255, 255, 0.65);
1520 box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
1521 display: flex;
1522 align-items: center;
1523 justify-content: center;
1524}
1525
1526/* ---- 歌曲信息 ---- */
1527.music-header {
1528 position: relative;
1529 z-index: 1;
1530 display: flex;
1531 flex-direction: column;
1532 align-items: center;
1533 /* 自定义导航栏:顶部预留状态栏高度 */
1534 padding: calc(var(--status-bar-height, 0px) + 120rpx) 40rpx 40rpx;
1535}
1536
1537.music-pic {
1538 width: 360rpx;
1539 height: 360rpx;
1540 border-radius: 24rpx;
1541 box-shadow: 0 12rpx 32rpx rgba(0, 0, 0, 0.15);
1542}
1543
1544/* 封面淡入(切歌时柔和过渡) */
1545.pic-fade {
1546 animation: picFadeIn 0.5s ease-out both;
1547}
1548@keyframes picFadeIn {
1549 from {
1550 opacity: 0;
1551 transform: scale(0.96);
1552 }
1553 to {
1554 opacity: 1;
1555 transform: scale(1);
1556 }
1557}
1558
1559.music-pic.placeholder {
1560 display: flex;
1561 align-items: center;
1562 justify-content: center;
1563 background: #e8eaed;
1564 color: #c0c4cc;
1565 font-size: 96rpx;
1566}
1567
1568.music-name {
1569 margin-top: 36rpx;
1570 font-size: 38rpx;
1571 font-weight: 600;
1572 color: #303133;
1573 text-align: center;
1574}
1575
1576.music-singer {
1577 margin-top: 12rpx;
1578 font-size: 28rpx;
1579 color: var(--text-muted, #909399);
1580}
1581
1582/* ---- 歌词 ---- */
1583.lyric-area {
1584 position: relative;
1585 z-index: 1;
1586 flex: 1;
1587 min-height: 0;
1588 padding: 0 40rpx;
1589 overflow: hidden;
1590}
1591
1592.lyric-scroll {
1593 height: 100%;
1594}
1595
1596.lyric-content {
1597 display: flex;
1598 flex-direction: column;
1599 padding: 40rpx 0;
1600}
1601
1602/* 上下占位,让 scroll-into-view 滚动时当前行落在视区中部 */
1603.lyric-spacer {
1604 height: 30vh;
1605}
1606
1607.lyric-line {
1608 padding: 18rpx 0;
1609 font-size: 30rpx;
1610 color: rgba(48, 49, 51, 0.4);
1611 text-align: center;
1612 transition: color 0.35s cubic-bezier(0.25, 0.1, 0.25, 1), font-size 0.35s cubic-bezier(0.25, 0.1, 0.25, 1), transform 0.35s cubic-bezier(0.25, 0.1, 0.25, 1);
1613 transform: scale(1);
1614}
1615
1616.lyric-line.active {
1617 color: var(--theme-color-dark, #1ba56a);
1618 font-size: 36rpx;
1619 font-weight: 600;
1620 transform: scale(1.08);
1621}
1622
1623.lyric-empty {
1624 color: #c0c4cc;
1625}
1626
1627/* ---- 进度条(控制区下方) ---- */
1628.progress-area {
1629 position: relative;
1630 z-index: 1;
1631 display: flex;
1632 align-items: center;
1633 padding: 8rpx 32rpx 0;
1634}
1635
1636.time-text {
1637 font-size: 24rpx;
1638 color: var(--text-muted, #909399);
1639 width: 80rpx;
1640}
1641
1642.progress-slider {
1643 flex: 1;
1644 margin: 0 16rpx;
1645}
1646
1647/* ---- 主控制按钮(上一曲/播放/下一曲,一行对称) ---- */
1648.controls-main {
1649 position: relative;
1650 z-index: 1;
1651 display: flex;
1652 align-items: center;
1653 justify-content: center;
1654 /* 歌词区 flex:1 撑满中间,控制区贴近底部,只保留适度间距 */
1655 padding: 16rpx 16rpx 8rpx;
1656}
1657
1658/* 上一曲与下一曲围绕播放键等距对称 */
1659.ctrl-prev {
1660 margin-right: 72rpx;
1661}
1662
1663.ctrl-next {
1664 margin-left: 72rpx;
1665}
1666
1667/* ---- 次级控制按钮(模式/音质/收藏/下载) ---- */
1668.controls-sub {
1669 position: relative;
1670 z-index: 1;
1671 display: flex;
1672 align-items: center;
1673 justify-content: center;
1674 gap: 40rpx;
1675 padding: 8rpx 16rpx 16rpx;
1676}
1677
1678.ctrl-btn {
1679 display: flex;
1680 align-items: center;
1681 justify-content: center;
1682 min-width: 88rpx;
1683 height: 88rpx;
1684 flex-shrink: 0;
1685}
1686
1687.play-btn {
1688 flex-shrink: 0;
1689 width: 130rpx;
1690 height: 130rpx;
1691 border-radius: 65rpx;
1692 background: var(--theme-color, #31c27c);
1693 box-shadow: 0 8rpx 28rpx rgba(var(--theme-color-rgb, 49, 194, 124), 0.5);
1694}
1695
1696.mode-text {
1697 font-size: 20rpx;
1698 color: var(--text-secondary, #606266);
1699}
1700
1701.quality-text {
1702 font-size: 20rpx;
1703 color: var(--text-secondary, #606266);
1704 border: 1rpx solid #c0c4cc;
1705 border-radius: 20rpx;
1706 padding: 4rpx 12rpx;
1707}
1708
1709/* ---- 音质选择弹层 ---- */
1710.quality-mask {
1711 position: fixed;
1712 top: 0;
1713 left: 0;
1714 right: 0;
1715 bottom: 0;
1716 background: rgba(0, 0, 0, 0.5);
1717 z-index: 999;
1718}
1719
1720.quality-sheet {
1721 position: fixed;
1722 left: 0;
1723 right: 0;
1724 bottom: 0;
1725 background: #fff;
1726 border-radius: 24rpx 24rpx 0 0;
1727 padding-bottom: calc(env(safe-area-inset-bottom));
1728 z-index: 1000;
1729}
1730
1731.quality-sheet-title {
1732 padding: 32rpx;
1733 font-size: 28rpx;
1734 font-weight: 600;
1735 color: #303133;
1736 text-align: center;
1737 border-bottom: 1rpx solid #f5f6f8;
1738}
1739
1740/* ============ 分享海报弹层 ============ */
1741.share-canvas {
1742 /* 离屏画布:只做绘制载体,CSS 尺寸 = 绘制坐标系(1000×1250),
1743 导出时按同分辨率输出;放在视口右侧屏幕外避免遮挡 */
1744 position: fixed;
1745 left: 9999px;
1746 top: 0;
1747 width: 1000px;
1748 height: 1250px;
1749}
1750
1751.share-sheet {
1752 max-height: 82vh;
1753 overflow-y: auto;
1754}
1755
1756.share-state {
1757 display: flex;
1758 flex-direction: column;
1759 align-items: center;
1760 gap: 14rpx;
1761 padding: 44rpx 40rpx 40rpx;
1762}
1763
1764.share-state-text {
1765 font-size: 30rpx;
1766 font-weight: 600;
1767 color: #303133;
1768}
1769
1770.share-state-text.is-error {
1771 color: #f56c6c;
1772 font-weight: 500;
1773 word-break: break-all;
1774 text-align: center;
1775}
1776
1777.share-state-hint {
1778 font-size: 22rpx;
1779 color: #909399;
1780 text-align: center;
1781}
1782
1783.share-poster {
1784 display: block;
1785 width: 380rpx;
1786 height: 475rpx;
1787 margin: 16rpx auto 8rpx;
1788 border-radius: 16rpx;
1789 box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.15);
1790 background: #f5f6f8;
1791}
1792
1793.quality-item {
1794 display: flex;
1795 align-items: center;
1796 justify-content: space-between;
1797 padding: 28rpx 40rpx;
1798 font-size: 30rpx;
1799 color: #303133;
1800 border-bottom: 1rpx solid #f5f6f8;
1801}
1802
1803.quality-item.active {
1804 color: var(--theme-color, #31c27c);
1805 font-weight: 600;
1806}
1807
1808.quality-item-name {
1809 flex: 1;
1810}
1811
1812.quality-item-check {
1813 color: var(--theme-color, #31c27c);
1814 font-size: 30rpx;
1815}
1816
1817.quality-item.cancel {
1818 color: var(--text-muted, #909399);
1819 justify-content: center;
1820 border-bottom: none;
1821}
1822
1823/* ---- 新建歌单弹层 ---- */
1824.list-name-editor {
1825 padding: 24rpx 32rpx 0;
1826}
1827
1828.list-name-input {
1829 width: 100%;
1830 height: 88rpx;
1831 padding: 0 24rpx;
1832 border-radius: 12rpx;
1833 background: #f7f8fa;
1834 font-size: 28rpx;
1835 color: #303133;
1836 box-sizing: border-box;
1837}
1838
1839.list-name-btn {
1840 margin: 24rpx 32rpx 0;
1841 background: var(--theme-color, #31c27c);
1842 color: #fff;
1843 border-radius: 40rpx;
1844 font-size: 30rpx;
1845}
1846
1847.list-name-btn[disabled] {
1848 opacity: 0.5;
1849}
1850
1851/* ---- 可视化 ---- */
1852.visualizer-area {
1853 position: relative;
1854 z-index: 1;
1855 padding: 0 48rpx calc(48rpx + env(safe-area-inset-bottom));
1856 display: flex;
1857 justify-content: center;
1858}
1859
1860.visualizer-canvas {
1861 width: 100%;
1862 height: 160rpx;
1863}
1864
1865/* ============ 超窄屏横屏(<640px,老机型 / 分屏):保留单列并允许整页滚动 ============ */
1866@media (orientation: landscape) and (max-width: 639px) {
1867 .play-detail {
1868 overflow-y: auto;
1869 }
1870 /* 子项按内容高度排布,不再参与 flex 压缩 */
1871 .music-header,
1872 .controls-main,
1873 .controls-sub,
1874 .progress-area,
1875 .visualizer-area,
1876 .lyric-area {
1877 flex-shrink: 0;
1878 }
1879 /* 歌词区保留可读高度(按视口高度的 40%) */
1880 .lyric-area {
1881 min-height: 40vh;
1882 }
1883}
1884
1885/* ============ 手机横屏紧凑分栏(640-959px 宽) ============ */
1886/* 横屏下 rpx 会随屏幕宽度整体放大,单列布局又受限于高度,
1887 因此改为左右分栏 + px 固定尺寸,让封面/控制/歌词在一屏内完整呈现 */
1888@media (orientation: landscape) and (min-width: 640px) and (max-width: 959px) {
1889 .play-detail {
1890 display: grid;
1891 grid-template-columns: minmax(0, 46%) minmax(0, 54%);
1892 grid-template-rows: auto auto auto auto 1fr;
1893 grid-template-areas:
1894 'header lyric'
1895 'controls lyric'
1896 'sub lyric'
1897 'progress lyric'
1898 'viz lyric';
1899 overflow: hidden;
1900 }
1901
1902 /* ---- 左列:歌曲信息 ---- */
1903 .music-header {
1904 grid-area: header;
1905 padding: 10px 20px 2px;
1906 }
1907 .music-pic {
1908 width: 92px;
1909 height: 92px;
1910 }
1911 .music-pic.placeholder {
1912 font-size: 30px;
1913 }
1914 .music-name {
1915 margin-top: 6px;
1916 font-size: 15px;
1917 }
1918 .music-singer {
1919 margin-top: 2px;
1920 font-size: 11px;
1921 }
1922
1923 /* ---- 左列:主控制 ---- */
1924 .controls-main {
1925 grid-area: controls;
1926 padding: 4px 8px 0;
1927 }
1928 .play-btn {
1929 width: 48px;
1930 height: 48px;
1931 border-radius: 24px;
1932 }
1933 .ctrl-prev {
1934 margin-right: 24px;
1935 }
1936 .ctrl-next {
1937 margin-left: 24px;
1938 }
1939
1940 /* ---- 左列:次级控制 ---- */
1941 .controls-sub {
1942 grid-area: sub;
1943 padding: 2px 8px 0;
1944 }
1945 .mode-text,
1946 .quality-text {
1947 font-size: 10px;
1948 }
1949
1950 /* ---- 左列:进度条 ---- */
1951 .progress-area {
1952 grid-area: progress;
1953 padding: 2px 20px 0;
1954 }
1955 .time-text {
1956 font-size: 10px;
1957 }
1958
1959 /* ---- 左列:可视化 ---- */
1960 .visualizer-area {
1961 grid-area: viz;
1962 align-self: end;
1963 padding: 0 20px 6px;
1964 }
1965 .visualizer-canvas {
1966 height: 32px;
1967 }
1968
1969 /* ---- 右列:歌词占满整列高度 ---- */
1970 .lyric-area {
1971 grid-area: lyric;
1972 height: 100%;
1973 min-height: 0;
1974 align-self: stretch;
1975 padding: 0 20px;
1976 }
1977 .lyric-line {
1978 padding: 5px 0;
1979 font-size: 14px;
1980 }
1981 .lyric-line.active {
1982 font-size: 17px;
1983 }
1984 .lyric-spacer {
1985 height: 18vh;
1986 }
1987}
1988
1989/* ============ 大屏横屏适配(平板横屏 / 桌面宽窗) ============ */
1990/* 竖屏手机完全不受影响;仅在横屏且宽度足够时,播放页改为左右分栏:
1991 左侧 = 封面 + 控制 + 进度 + 可视化,右侧 = 歌词占满整列高度 */
1992@media (orientation: landscape) and (min-width: 960px) {
1993 .play-detail {
1994 display: grid;
1995 grid-template-columns: minmax(0, 44%) minmax(0, 56%);
1996 grid-template-rows: auto auto auto auto 1fr;
1997 grid-template-areas:
1998 'header lyric'
1999 'controls lyric'
2000 'sub lyric'
2001 'progress lyric'
2002 'viz lyric';
2003 }
2004
2005 /* ---- 左列:歌曲信息 ---- */
2006 .music-header {
2007 grid-area: header;
2008 padding: calc(var(--status-bar-height, 0px) + 30rpx) 40rpx 10rpx;
2009 }
2010 .music-pic {
2011 width: 280px;
2012 height: 280px;
2013 }
2014 .music-pic.placeholder {
2015 font-size: 72px;
2016 }
2017 .music-name {
2018 margin-top: 24px;
2019 font-size: 24px;
2020 }
2021 .music-singer {
2022 margin-top: 8px;
2023 font-size: 16px;
2024 }
2025
2026 /* ---- 左列:主控制 ---- */
2027 .controls-main {
2028 grid-area: controls;
2029 padding: 10rpx 16rpx 4rpx;
2030 }
2031 .play-btn {
2032 width: 76px;
2033 height: 76px;
2034 border-radius: 38px;
2035 }
2036 .ctrl-prev {
2037 margin-right: 40px;
2038 }
2039 .ctrl-next {
2040 margin-left: 40px;
2041 }
2042
2043 /* ---- 左列:次级控制 ---- */
2044 .controls-sub {
2045 grid-area: sub;
2046 padding: 4rpx 16rpx 8rpx;
2047 }
2048 .mode-text,
2049 .quality-text {
2050 font-size: 12px;
2051 }
2052
2053 /* ---- 左列:进度条 ---- */
2054 .progress-area {
2055 grid-area: progress;
2056 padding: 4rpx 40rpx 0;
2057 }
2058 .time-text {
2059 font-size: 13px;
2060 }
2061
2062 /* ---- 左列:可视化(贴近底部) ---- */
2063 .visualizer-area {
2064 grid-area: viz;
2065 align-self: end;
2066 padding: 0 40px 24px;
2067 }
2068 .visualizer-canvas {
2069 height: 72px;
2070 }
2071
2072 /* ---- 右列:歌词占满整列高度 ---- */
2073 .lyric-area {
2074 grid-area: lyric;
2075 height: 100%;
2076 min-height: 0;
2077 align-self: stretch;
2078 padding: 0 48rpx;
2079 }
2080 .lyric-line {
2081 padding: 10px 0;
2082 font-size: 18px;
2083 }
2084 .lyric-line.active {
2085 font-size: 22px;
2086 }
2087 .lyric-spacer {
2088 height: 26vh;
2089 }
2090}
2091
2092/* ============ 歌曲彩蛋动画层 ============ */
2093.easter-overlay {
2094 position: fixed;
2095 top: 0;
2096 left: 0;
2097 right: 0;
2098 bottom: 0;
2099 z-index: 50;
2100 overflow: hidden;
2101 /* 纯观赏层:不拦截任何点击,不影响播放操作 */
2102 pointer-events: none;
2103}
2104
2105.easter-particles {
2106 position: absolute;
2107 top: 0;
2108 left: 0;
2109 right: 0;
2110 bottom: 0;
2111}
2112
2113.easter-particle {
2114 position: absolute;
2115 bottom: -80rpx;
2116 /* 不用 will-change:避免为每个粒子强制创建独立合成层,低端设备上会与页面首帧渲染抢资源 */
2117}
2118
2119.easter-particle-icon {
2120 line-height: 1;
2121}
2122
2123/* 烟花:自下而上扩散淡出 */
2124.easter-fireworks .easter-particle {
2125 animation-name: eggFirework;
2126 animation-timing-function: ease-out;
2127 animation-fill-mode: both;
2128}
2129@keyframes eggFirework {
2130 0% {
2131 transform: translateY(0) scale(0.4);
2132 opacity: 0;
2133 }
2134 12% {
2135 opacity: 1;
2136 }
2137 100% {
2138 transform: translateY(-118vh) scale(1);
2139 opacity: 0;
2140 }
2141}
2142
2143/* 爱心 / 音符:自下而上 + 左右摇摆 + 旋转 */
2144.easter-hearts .easter-particle,
2145.easter-notes .easter-particle {
2146 animation-name: eggFloat;
2147 animation-timing-function: ease-in-out;
2148 animation-fill-mode: both;
2149}
2150@keyframes eggFloat {
2151 0% {
2152 transform: translate(0, 0) rotate(0deg);
2153 opacity: 0;
2154 }
2155 12% {
2156 opacity: 1;
2157 }
2158 50% {
2159 transform: translate(36rpx, -55vh) rotate(18deg);
2160 }
2161 100% {
2162 transform: translate(-36rpx, -115vh) rotate(-18deg);
2163 opacity: 0;
2164 }
2165}
2166
2167/* 星光:原地闪烁(粒子 top 定位) */
2168.easter-sparkle .easter-particle {
2169 bottom: auto;
2170 animation-name: eggTwinkle;
2171 animation-timing-function: ease-in-out;
2172 animation-iteration-count: infinite;
2173}
2174@keyframes eggTwinkle {
2175 0%,
2176 100% {
2177 transform: scale(0.5);
2178 opacity: 0.15;
2179 }
2180 50% {
2181 transform: scale(1.15);
2182 opacity: 1;
2183 }
2184}
2185
2186/* 流星:自右上向左下滑落渐隐 */
2187.easter-meteor .easter-particle {
2188 bottom: auto;
2189 top: 0;
2190 animation-name: eggMeteor;
2191 animation-timing-function: ease-in;
2192 animation-fill-mode: both;
2193}
2194@keyframes eggMeteor {
2195 0% {
2196 transform: translate(0, 0);
2197 opacity: 0;
2198 }
2199 8% {
2200 opacity: 1;
2201 }
2202 100% {
2203 transform: translate(-70vw, 120vh);
2204 opacity: 0;
2205 }
2206}
2207
2208/* 彩蛋文案卡片 */
2209.easter-card {
2210 position: absolute;
2211 top: 50%;
2212 left: 50%;
2213 transform: translate(-50%, -50%);
2214 z-index: 51;
2215 background: rgba(255, 255, 255, 0.92);
2216 border: 2rpx solid rgba(var(--theme-color-rgb, 49, 194, 124), 0.35);
2217 border-radius: 28rpx;
2218 padding: 36rpx 56rpx;
2219 text-align: center;
2220 box-shadow: 0 16rpx 48rpx rgba(0, 0, 0, 0.14);
2221}
2222.easter-card-title {
2223 display: block;
2224 font-size: 40rpx;
2225 font-weight: 700;
2226 color: var(--theme-color, #31c27c);
2227}
2228.easter-card-sub {
2229 display: block;
2230 margin-top: 12rpx;
2231 font-size: 24rpx;
2232 color: var(--text-muted, #909399);
2233}
2234</style>