diff --git a/android/app/src/main/assets/pulsewall/preset-music.html b/android/app/src/main/assets/pulsewall/preset-music.html index c03cfea..d68f634 100644 --- a/android/app/src/main/assets/pulsewall/preset-music.html +++ b/android/app/src/main/assets/pulsewall/preset-music.html @@ -561,6 +561,10 @@ body { .track.playing { background: rgba(34,197,94,.13); border-color: rgba(34,197,94,.38); } .track.playing .t-name { color: #86efac; } +/* 当前曲目已暂停:琥珀色,区别于播放中的绿色 */ +.track.paused { background: rgba(245,158,11,.10); border-color: rgba(245,158,11,.34); } +.track.paused .t-name { color: #fbbf24; } + .t-num { width: 4vh; height: 4vh; flex: 0 0 auto; @@ -571,6 +575,8 @@ body { color: #7dd3fc; } .track.playing .t-num { background: rgba(34,197,94,.2); color: #4ade80; } +.track.paused .t-num { background: rgba(245,158,11,.16); color: #fbbf24; } +.track.paused .t-go { color: #fbbf24; opacity: 1; } /* 播放中:序号位改为跳动的音量条 */ .t-num-play { padding: 0; } @@ -723,12 +729,16 @@ body { loop: '', // 随机(交叉箭头) shuffle: '', + // 唱片(同心圆):正在播放时显示 + disc: '', + // 耳机:未播放时显示 + head: '', // 单曲循环(带 1 的循环) + single: '', // 正在播放:声波 wave: '', // 普通:播放箭头 - arrow: '', - single: '' + arrow: '' }; // UI 音量上限。服务端 volume 比例基数与之一致(都是 100), // 因此换算直接用 VOL_MAX,不再单独维护基数常量。 @@ -754,7 +764,10 @@ body { duration: null, elapsed: null, progress: null, - remaining: null + remaining: null, + resumable: false, + startAt: 0, + stoppedAt: null }, // 播放方式:queue=顺序排队 / shuffle=随机 / repeat-one=单曲循环 playMode: "queue", @@ -951,6 +964,15 @@ body { p.elapsed = (typeof r.elapsed_sec === "number") ? r.elapsed_sec : null; p.progress = (typeof r.progress_pct === "number") ? r.progress_pct : null; p.remaining = (typeof r.remaining_sec === "number") ? r.remaining_sec : null; + p.resumable = !!r.resumable; + p.startAt = (typeof r.start_at === "number") ? r.start_at : 0; + p.stoppedAt = (typeof r.stopped_at === "number") ? r.stopped_at : null; + // 暂停时服务端会把 elapsed/progress 置 null,用停播位置推导 + if (!p.playing && typeof p.stoppedAt === "number") { + p.elapsed = Math.max(0, p.stoppedAt - p.startAt); + p.progress = p.duration > 0 ? (p.elapsed / p.duration) * 100 : 0; + p.remaining = Math.max(0, p.duration - p.elapsed); + } renderNowPlaying(); renderToggle(); return p; @@ -963,6 +985,15 @@ body { p.elapsed = (typeof r.elapsed_sec === "number") ? r.elapsed_sec : null; p.progress = (typeof r.progress_pct === "number") ? r.progress_pct : null; p.remaining = (typeof r.remaining_sec === "number") ? r.remaining_sec : null; + p.resumable = !!r.resumable; + p.startAt = (typeof r.start_at === "number") ? r.start_at : 0; + p.stoppedAt = (typeof r.stopped_at === "number") ? r.stopped_at : null; + // 暂停时服务端 elapsed/progress 为 null,用 stopped_at - start_at 推导 + if (!p.playing && typeof p.stoppedAt === "number") { + p.elapsed = Math.max(0, p.stoppedAt - p.startAt); + p.progress = p.duration > 0 ? (p.elapsed / p.duration) * 100 : 0; + p.remaining = Math.max(0, p.duration - p.elapsed); + } renderNowPlaying(); renderToggle(); // 注意:这里不能调 renderList()。 @@ -1153,11 +1184,17 @@ body { var path = t.path || t.file || ""; if (!path) { log("缺少 path 字段", "err"); return; } - // 如果点的就是当前正在播放的这首,不做任何操作,避免重新开始播放。 - // force=true 用于「继续播放」等明确需要重放的场景。 - if (!force && state.player.playing && state.player.source === path) { - log("正在播放这首,无需切换", ""); - return; + // 点当前曲目: + // - 正在播放 -> 无操作,避免打断 + // - 已暂停且可续播 -> 走 resume,从上次位置继续 + if (!force && state.player.source === path) { + if (state.player.playing) { + log("正在播放这首,无需切换", ""); + return; + } + if (state.player.resumable) { + return resumePlay(); + } } setPill("播放中…", "busy"); log("正在播放:" + (t.name || path)); @@ -1235,10 +1272,50 @@ body { } /* 单按钮切换:服务端 playing 为准 */ + /* 从暂停位置继续播放:调用 MCP resume,不再从头播放 */ + function resumePlay() { + var start = Math.round(state.player.startAt || 0); + setPill("续播中…", "busy"); + log("从 " + fmtDur(start) + " 续播", ""); + + callTool("resume", { volume: state.volume }).catch(function (e) { + // resume 失败时回退为从头播放 + log("续播失败:" + e.message + ",改为从头播放", "err"); + var t = currentTrackInfo(); + if (t && t.path) playTrack(t, true); + }); + + // 短暂等待后同步服务端状态 + return verifyResume(0); + } + + function verifyResume(attempt) { + return new Promise(function (resolve) { + setTimeout(function () { + syncPlayerStatus({ silent: true }).then(function (p) { + if (p.playing || attempt >= 8) { + setPill(p.playing ? "已连接" : "已连接", "on"); + if (p.playing) { + log("继续播放", "ok"); + startPolling(); + } + resolve(p); + } else { + resolve(verifyResume(attempt + 1)); + } + }); + }, attempt === 0 ? 400 : 350); + }); + } + function togglePlay() { if (state.player.playing) { return stopPlay(); } + // MCP 已支持续播:优先从上次停止位置继续 + if (state.player.resumable) { + return resumePlay(); + } var t = currentTrackInfo(); if (!t || !t.path) { log("还没有可播放的曲目,请先从右侧选一首", "err"); @@ -1353,7 +1430,7 @@ body { var wrap = $("prog-wrap"), fill = $("prog-fill"); if (!p.source) { - if (disc) { disc.className = ""; disc.textContent = "🎧"; } + if (disc) { disc.className = ""; disc.innerHTML = ICON.head; } if (title) title.textContent = "未在播放"; if (sub) sub.textContent = "从右侧选一首,或让 AI 帮你找歌"; if (wrap) wrap.style.visibility = "hidden"; @@ -1361,6 +1438,7 @@ body { } if (title) title.textContent = p.title || p.source; + // 曲目变化时给唱片一次切换动效 if (disc && p.source !== FX._lastSource) { FX._lastSource = p.source; @@ -1368,21 +1446,28 @@ body { } if (p.playing) { - if (disc) { disc.className = "spinning"; disc.textContent = "🎵"; } - if (sub) { - var bits = []; - if (typeof p.duration === "number") bits.push("总长 " + fmtDur(p.duration)); - if (typeof p.remaining === "number") bits.push("剩余 " + fmtDur(p.remaining)); - sub.textContent = bits.join(" · ") || "正在播放"; - } - if (wrap) wrap.style.visibility = "visible"; - if (fill) fill.style.width = Math.max(0, Math.min(100, p.progress || 0)) + "%"; - + if (disc) { disc.className = "spinning"; disc.innerHTML = ICON.disc; } } else { + // 暂停时唱片停止旋转,显示暂停图标 if (disc) { disc.className = ""; disc.innerHTML = ICON.pause; } - if (sub) sub.textContent = "已暂停 · 按播放键继续"; - if (wrap) wrap.style.visibility = "hidden"; } + + // 时间信息:播放中 / 暂停都显示,暂停时明确标注 + if (sub) { + var bits = []; + if (typeof p.elapsed === "number") bits.push("已播 " + fmtDur(p.elapsed)); + if (typeof p.duration === "number") bits.push("总长 " + fmtDur(p.duration)); + // 暂停时 remaining 由 stoppedAt-startAt 推导出来,也应显示 + if (typeof p.remaining === "number") { + bits.push("剩余 " + fmtDur(p.remaining)); + } + var text = bits.join(" · ") || "—"; + sub.textContent = p.playing ? text : ("已暂停 · " + text); + } + + // 关键修改:暂停时进度条不再隐藏,保留当前进度 + if (wrap) wrap.style.visibility = "visible"; + if (fill) fill.style.width = Math.max(0, Math.min(100, p.progress || 0)) + "%"; } /* 只刷新「哪一行在播放」的高亮,不重建 DOM。 @@ -1421,12 +1506,13 @@ body { var idx = parseInt(row.getAttribute("data-idx"), 10); var t = (isNaN(idx) ? null : state.tracks[idx]); var path = t ? (t.path || t.file || "") : ""; - var playing = !!(src && path && src === path); + var isCurrent = !!(src && path && src === path); + var playing = isCurrent && state.player.playing; + var paused = isCurrent && !state.player.playing; - if (playing) row.classList.add("playing"); - else row.classList.remove("playing"); + if (playing) row.classList.add("playing"); else row.classList.remove("playing"); + if (paused) row.classList.add("paused"); else row.classList.remove("paused"); - // 序号位:数字 <-> 跳动的音量条 var num = row.querySelector(".t-num"); if (num) { if (playing) { @@ -1436,15 +1522,13 @@ body { } } else { num.classList.remove("t-num-play"); - num.textContent = String(idx + 1); + num.innerHTML = paused ? ICON.pause : String(idx + 1); } } - // 右侧图标:箭头 <-> 声波 var go = row.querySelector(".t-go"); - if (go) go.innerHTML = playing ? ICON.wave : ICON.arrow; + if (go) go.innerHTML = playing ? ICON.wave : (paused ? ICON.play : ICON.arrow); } - // 记录当前渲染绑定的源 renderList._lastSource = src; } @@ -1491,23 +1575,29 @@ body { var t = arr[i] || {}; var name = t.name || t.path || ("曲目 " + (i + 1)); var path = t.path || ""; - // 用服务端 player_status 的 source 判定,state.playing 是已废弃字段 + // 当前曲目分三态:播放中 / 已暂停 / 普通 var src = state.player.source; - var playing = !!(src && path && src === path); + var isCurrent = !!(src && path && src === path); + var playing = isCurrent && state.player.playing; + var paused = isCurrent && !state.player.playing; + var stateClass = playing ? " playing" : (paused ? " paused" : ""); var bits = []; if (t.duration_sec) bits.push(fmtDur(t.duration_sec)); if (t.size_mb) bits.push(Number(t.size_mb).toFixed(1) + " MB"); html += - '