From 8f1e150887c708a985fb67da42a83b626de81a8c Mon Sep 17 00:00:00 2001 From: ShellMonster Date: Fri, 20 Nov 2026 17:10:41 +0800 Subject: [PATCH 1/4] test: stabilize desktop release regression checks --- .github/workflows/macos.yml | 2 +- .github/workflows/nightly.yml | 29 +++++++++++++----- .github/workflows/windows-e2e.yml | 6 ++++ internal/app/playmode_wiring_test.go | 19 ++++++------ internal/e2e/fixture_liked/main.go | 39 ++++++++++-------------- internal/e2e/likedplaylist_test.go | 28 ++++++++--------- internal/ui/likedplaylistfixture_test.go | 12 +++----- 7 files changed, 72 insertions(+), 63 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 7585e09b..ab746ac9 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -119,7 +119,7 @@ jobs: # 没有别的实例,这一族本来能过;但**本地**跑的时候用户机器上几乎总是 # 跑着这个应用,而那一轮会抢不到锁、然后自己退出。 BIU_RUN_MYGO_E2E=1 go test -tags e2e ./internal/e2e \ - -run 'TestMyGoAutomationDrivesNativeUIAndCapturesIt|TestTheApplicationMenu|TestTheStatsPage|TestTheListProgressBarIsAProgressIndicatorWithAName' \ + -run 'TestMyGoAutomationDrivesNativeUIAndCapturesIt|TestTheApplicationMenu|TestTheStatsPage|TestTheListProgressBarIsAProgressIndicatorWithAName|TestThePlayerHasOnlyTheLikeEntry' \ -count=1 -timeout 300s artifacts: diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 0c369316..ff86f0c5 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -14,9 +14,17 @@ permissions: jobs: race: - name: Race detector on concurrent packages - runs-on: ubuntu-24.04 + name: Race detector (${{ matrix.runner }}) + runs-on: ${{ matrix.runner }} timeout-minutes: 45 + strategy: + fail-fast: false + matrix: + include: + - runner: ubuntu-24.04 + packages: ./internal/service/audio/... ./internal/platform ./internal/app ./internal/ui/widgets/imgcache + - runner: macos-15-intel + packages: ./internal/service/audio steps: - name: Check out source @@ -30,12 +38,17 @@ jobs: cache-dependency-path: go.sum - name: Test with -race - run: >- - go test -race -count=1 - ./internal/service/audio/... - ./internal/platform - ./internal/app - ./internal/ui/widgets/imgcache + shell: bash + run: | + set -euo pipefail + read -ra packages <<< "$PACKAGES" + if [[ "$RUNNER_OS" == Linux ]]; then + go list "${packages[@]}" | grep -vxF 'github.com/ShellMonster/PudMusic/internal/service/audio' | xargs go test -race -count=1 -p 4 + else + go test -race -count=1 -p 4 "${packages[@]}" + fi + env: + PACKAGES: ${{ matrix.packages }} govulncheck: name: Known vulnerabilities diff --git a/.github/workflows/windows-e2e.yml b/.github/workflows/windows-e2e.yml index 751b7613..afccaf25 100644 --- a/.github/workflows/windows-e2e.yml +++ b/.github/workflows/windows-e2e.yml @@ -32,6 +32,9 @@ on: - "internal/service/**" - "automation_e2e.go" - "main.go" + - "entry_desktop.go" + - "go.mod" + - "go.sum" - "mygo.json" - "resources/windows/**" - ".github/workflows/windows-e2e.yml" @@ -45,6 +48,9 @@ on: - "internal/service/**" - "automation_e2e.go" - "main.go" + - "entry_desktop.go" + - "go.mod" + - "go.sum" - "mygo.json" - "resources/windows/**" - ".github/workflows/windows-e2e.yml" diff --git a/internal/app/playmode_wiring_test.go b/internal/app/playmode_wiring_test.go index c34870ca..86a141f0 100644 --- a/internal/app/playmode_wiring_test.go +++ b/internal/app/playmode_wiring_test.go @@ -148,7 +148,9 @@ func TestSequenceStopsAfterTheLastSong(t *testing.T) { // 走完三遍还是同一首:前两遍换新播放器,第三遍(重放)不换——换了的症状是 // 进度条从头开始闪一下、句柄来回收去,而这是同一首从头再放,本来就该那样。 func TestSingleReplaysWithoutMovingOn(t *testing.T) { - paths := shorts(t, 3) + paths := shorts(t, 2) + first := shortenWAV(t, readFile(t, fixturePath(t, "stereo16.wav")), 0.75) + paths[0] = writeBytes(t, t.TempDir(), "a.wav", first) a := newApp(t) if err := a.MountSettings(filepath.Join(t.TempDir(), app.SettingsFileName)); err != nil { @@ -159,18 +161,15 @@ func TestSingleReplaysWithoutMovingOn(t *testing.T) { t.Fatal(err) } - // a 放完 → 还是 a(从头再放)→ 还是 a ……连着三轮,标题一次都不许变。 - // - // ⚠️ 每一轮都要**真的看见这一首放完**:只断「标题是 a 且在放」的话, - // 起播那一瞬间就成立了,整条等于没跑。判据是位置——先等它走到末尾 - // (reachedEnd),再等它回到开头(重放过了)。 + // 自然结束时进度直接回到开头。用跨过中点后回到前半段的进度验证重播。 for round := range 3 { - waitFor(t, 6*time.Second, "单曲没有放到头", func() bool { - return reachedEnd(a.Snapshot()) + waitFor(t, 6*time.Second, "单曲没有播放到后半段", func() bool { + st := a.Snapshot() + return st.Title == "a" && st.Playing && st.Position > st.Duration/2 }) - waitFor(t, 3*time.Second, "单曲没有从头再放", func() bool { + waitFor(t, 6*time.Second, "单曲没有从头再放", func() bool { st := a.Snapshot() - return st.Title == "a" && st.Playing && st.Position < 40*time.Millisecond + return st.Title == "a" && st.Playing && st.Position > 0 && st.Position < st.Duration/2 }) if got := a.Queue().CurrentIndex(); got != 0 { t.Fatalf("第 %d 轮之后当前项在下标 %d,want 0(单曲播放一步都不挪)", round+1, got) diff --git a/internal/e2e/fixture_liked/main.go b/internal/e2e/fixture_liked/main.go index 188aaac4..bbac8249 100644 --- a/internal/e2e/fixture_liked/main.go +++ b/internal/e2e/fixture_liked/main.go @@ -35,12 +35,12 @@ package main // (id 100)——这是「已绑定」那一档,喜欢不再问。 import ( + "bytes" + "context" "encoding/json" - "fmt" "log" "net/http" "net/http/httptest" - "net/url" "os" "path/filepath" "strconv" @@ -70,9 +70,16 @@ func main() { } a := app.New() + if err := ui2.MountSettings(a); err != nil { + log.Fatalf("加载喜欢歌单设置:%v", err) + } cli := bili.NewClient(bili.Options{Transport: srv.Client().Transport}) cli.TestOnlyPointHostsAtFixture(srv.URL) - a.MountLogin(app.NewMemoryStore("liked-fixture"), cli) + store := app.NewMemoryStore("liked-fixture") + if err := store.Save(context.Background(), app.Session{SESSDATA: "fixture", DedeUserID: "9527"}); err != nil { + log.Fatalf("设置测试登录态:%v", err) + } + a.MountLogin(store, cli) tmp, err := os.MkdirTemp("", "liked-fixture-") if err != nil { log.Fatalf("造临时目录:%v", err) @@ -103,13 +110,16 @@ func main() { // seedLikedSettings 往数据目录写一份「已绑定喜欢歌单」的 settings.json。 // // ⚠️ **信封是设置文件的真形状**(`schemaVersion` + `appSettings`),只多写 -// `likedPlaylist` 那一格——其余键让 `DefaultSettings` 补上。 +// `likedFolder` 那一格——其余键让 `DefaultSettings` 补上。 func seedLikedSettings(dataDir string) { + if err := os.MkdirAll(dataDir, 0o700); err != nil { + log.Fatalf("创建测试数据目录:%v", err) + } settings := map[string]any{ "schemaVersion": 1, "appSettings": map[string]any{ "isMuted": true, - "likedPlaylist": map[string]any{ + "likedFolder": map[string]any{ "folderId": boundFolderID, "title": "绑定的那一格", }, @@ -236,21 +246,7 @@ func serveMedia(w http.ResponseWriter, r *http.Request) { http.Error(w, "读不到 FLAC 素材: "+err.Error(), http.StatusInternalServerError) return } - start := 0 - if h := r.Header.Get("Range"); strings.HasPrefix(h, "bytes=") { - start, _ = strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(h, "bytes="), "-")) - } - if start > len(data) { - http.Error(w, "越界", http.StatusRequestedRangeNotSatisfiable) - return - } - w.Header().Set("Content-Length", fmt.Sprint(len(data)-start)) - if start > 0 { - w.Header().Set("Content-Range", - fmt.Sprintf("bytes %d-%d/%d", start, len(data)-1, len(data))) - w.WriteHeader(http.StatusPartialContent) - } - _, _ = w.Write(data[start:]) + http.ServeContent(w, r, "a.flac", time.Time{}, bytes.NewReader(data)) } // fixtureRoot 是仓库根(E2E 测试在仓库根下 `go build` 这台 fixture)。 @@ -268,6 +264,3 @@ func writeJSON(w http.ResponseWriter, v any) { w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(v) } - -// _ = url 引着它防未使用报错:r.PostForm 的形状靠它。 -var _ = url.Values{} diff --git a/internal/e2e/likedplaylist_test.go b/internal/e2e/likedplaylist_test.go index 85ce21e4..28cf7d1f 100644 --- a/internal/e2e/likedplaylist_test.go +++ b/internal/e2e/likedplaylist_test.go @@ -55,8 +55,7 @@ func TestThePlayerHasOnlyTheLikeEntry(t *testing.T) { t.Skip("设置 BIU_RUN_MYGO_E2E=1 才运行真窗口 E2E") } - client, window, stop := startLikedFixture(t) - defer stop() + client, window := startLikedFixture(t) // 「喜欢」在:fixture 里「赞没赞」那一问已经回了(relation 里 like=false)。 if !waitForTree(t, client, window, "喜欢", 20*time.Second) { @@ -88,8 +87,8 @@ func TestThePlayerHasOnlyTheLikeEntry(t *testing.T) { // startLikedFixture 编起 `fixture_liked`,等 automation socket 起来。 // -// 返回 automation 客户端、第一个内容窗口的 id,和收尾。 -func startLikedFixture(t *testing.T) (*automationClient, int, func()) { +// 返回 automation 客户端和第一个内容窗口的 id。 +func startLikedFixture(t *testing.T) (*automationClient, int) { t.Helper() ctx, cancel := context.WithCancel(context.Background()) socketDir, socket, err := makeAutomationSocket() @@ -124,30 +123,31 @@ func startLikedFixture(t *testing.T) (*automationClient, int, func()) { _ = os.RemoveAll(socketDir) t.Fatalf("启动喜欢歌单 fixture:%v", err) } - stop := func() { + t.Cleanup(func() { cancel() waitForFixtureExit(t, cmd) _ = os.RemoveAll(socketDir) - } + }) conn := waitForAutomationSocket(t, socket, cmd, &stdout, &stderr) + t.Cleanup(func() { _ = conn.Close() }) client := &automationClient{conn: conn, enc: json.NewEncoder(conn), dec: bufio.NewReader(conn)} window := firstContentWindow(t, client) - return client, window, stop + return client, window } -// openFullWindow 点开满屏播放器:按播放条上那张封面(`当前封面`那一项)。 -// -// ⚠️ **按 id 按**:封面的无障碍名「当前封面」在树上有,但它不是一枚 -// `act` 按得动的 `button`(它是一张照片)。`act` 的 press 对任何节点都是 -// 「对它中心点按一下」——和 `tt.ClickAt` 在无头版里开满屏是同一路。 +// openFullWindow 通过原生无障碍树中可点击的封面容器打开满屏播放器。 func openFullWindow(t *testing.T, client *automationClient, window int) { t.Helper() + const coverLabel = "当前封面的操作" + if !waitForTree(t, client, window, coverLabel, 20*time.Second) { + t.Fatalf("树上找不到 %q:\n%s", coverLabel, treeDump(t, client, window)) + } id := findNodeID(t, client, window, func(n navNode) bool { - return n.Label == "当前封面" + return n.Label == coverLabel }) if id == "" { - t.Fatalf("树上找不到「当前封面」:\n%s", treeDump(t, client, window)) + t.Fatalf("树上找不到 %q:\n%s", coverLabel, treeDump(t, client, window)) } if err := automationCall(client, 610, "act", map[string]any{ "window": window, diff --git a/internal/ui/likedplaylistfixture_test.go b/internal/ui/likedplaylistfixture_test.go index 4f9fbdd2..b227fc36 100644 --- a/internal/ui/likedplaylistfixture_test.go +++ b/internal/ui/likedplaylistfixture_test.go @@ -113,12 +113,10 @@ func newLikedBindShell(t *testing.T, f *biliFixture, boundID int64) (*Shell, *my if err := s.app.Enqueue(likeItem()); err != nil { t.Fatalf("把在线的那首放进队列:%v", err) } - // ⚠️ **等歌真的放起来**:`Enqueue` 把第一项放起来是异步的(`a.player` - // 要等 goroutine 装上),`Snapshot().HasTrack`(= `player != nil`)要等 - // 那一趟回来才 true。播放条的封面、满屏的入口都拿 `HasTrack` 当门—— - // 不等它的话,用例拿到的第一帧封面还没画出来,满屏那一条「点开全屏」 - // 就找不到锚点。喜欢心摆出来靠 `Likeable()`(它看队列当前项,不看 - // `HasTrack`),那一档不用等;这里等的是**封面 / 满屏**这一头。 - waitFrames(t, tt, "歌放起来了", func() bool { return s.app.Snapshot().HasTrack }) + // 播放器可能在一帧绘制结束后才装上,等下一帧实际画出可以点的封面。 + waitFrames(t, tt, "当前封面出现", func() bool { + _, ok := tt.Find("当前封面") + return ok + }) return s, tt } From 7a44d76f0e63d504b46d4d619038fc2527589b81 Mon Sep 17 00:00:00 2001 From: ShellMonster Date: Fri, 20 Nov 2026 17:10:41 +0800 Subject: [PATCH 2/4] chore: prepare 1.2.6 release --- CHANGELOG.md | 16 ++++++++++++++++ RELEASE-NOTES.md | 13 +++++++++++++ go.mod | 2 +- mygo.json | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 376d69b2..00235dbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,22 @@ --- +## 1.2.6 + +桌面红心与收藏夹同步,首页新增热门歌手,搜索结果新增创作者预览。 + +### 收藏与搜索 + +- 播放条、全屏播放器、迷你播放器和刘海播放器根据绑定的 B 站收藏夹显示红心状态,支持添加和移除。切换账号或绑定时会清除旧状态(#885)。 +- 首页新增热门歌手入口。搜索结果展示匹配的创作者,切换关键词或离开搜索时取消在途请求(#884)。 +- 按 `/` 聚焦搜索框时同时打开搜索建议(#883)。 + +### 工程 + +- MyGo 升至 v0.10.0。平台入口拆分为桌面和移动端,调整共享的登录、播放意图和 AAC 解码逻辑(#886、#888、#889、#890)。 +- Go 升至 1.27.4,修复标准库 `net/http` 的 GO-2026-6859。 +- macOS CI 增加喜欢入口的原生回归。音频主包的夜间并发测试在 macOS 上运行,Linux 继续验证其余并发包。 + ## 1.2.5 全屏播放器封面墙、播放跳转平滑处理、搜索与滚动位置修复。 diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 49824d74..bbd955e5 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -102,6 +102,19 @@ --- +## 1.2.6 + +这版把播放器的红心和你绑定的 B 站收藏夹连起来,也让找歌手更方便。 + +### 播放 + +- 播放条、全屏播放器和迷你播放器的红心会显示歌曲是否已加入绑定的收藏夹。再点一次可从该收藏夹移除。 + +### 搜索 + +- 首页可以从热门歌手直接开始搜索,搜索结果会预览匹配的创作者。 +- 按 `/` 聚焦搜索框时会同时打开搜索建议。 + ## 1.2.5 这版可以用封面浏览播放队列,也让播放跳转和页面切换更顺手。 diff --git a/go.mod b/go.mod index bc99ead6..25ecdb1c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/ShellMonster/PudMusic -go 1.27.3 +go 1.27.4 require ( github.com/Eyevinn/mp4ff v0.62.0 diff --git a/mygo.json b/mygo.json index d21cb5ee..4042a882 100644 --- a/mygo.json +++ b/mygo.json @@ -2,7 +2,7 @@ "name": "布丁音乐", "slug": "pudmusic", "identifier": "io.github.shellmonster.biu", - "version": "1.2.5", + "version": "1.2.6", "out": "build", "urlSchemes": ["pudmusic"], "fileAssociations": [ From f215bd23222d0a9c87aea1425e086045ae98594b Mon Sep 17 00:00:00 2001 From: ShellMonster Date: Fri, 20 Nov 2026 17:17:53 +0800 Subject: [PATCH 3/4] ci: remove retired progress bar test filter --- .github/workflows/macos.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index ab746ac9..6b1ce560 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -105,9 +105,7 @@ jobs: # 按标题找栏、点「设置…」换页 # - TestTheStatsPage:听歌统计那一族,它在**真窗口**上按顶栏那枚 # 图标进统计页 - # - TestTheListProgressBarIsAProgressIndicatorWithAName:列表行下面那条 - # 进度条(票 #703 的 C 项),它断的是**无障碍树**里那一项的 - # 角色 / 值 / 名字——**只有真窗口 + automation 才读得到** + # - TestThePlayerHasOnlyTheLikeEntry:播放条和满屏播放器的红心入口 # # 为什么合成一条命令:它们各自都要**把整个应用编一遍**,而 CI 机器上 # 那一步不便宜——拆成两条命令就是编两遍,第二遍编的时候机器正忙着, @@ -119,7 +117,7 @@ jobs: # 没有别的实例,这一族本来能过;但**本地**跑的时候用户机器上几乎总是 # 跑着这个应用,而那一轮会抢不到锁、然后自己退出。 BIU_RUN_MYGO_E2E=1 go test -tags e2e ./internal/e2e \ - -run 'TestMyGoAutomationDrivesNativeUIAndCapturesIt|TestTheApplicationMenu|TestTheStatsPage|TestTheListProgressBarIsAProgressIndicatorWithAName|TestThePlayerHasOnlyTheLikeEntry' \ + -run '^(TestMyGoAutomationDrivesNativeUIAndCapturesIt|TestTheApplicationMenu|TestTheStatsPage|TestThePlayerHasOnlyTheLikeEntry)$' \ -count=1 -timeout 300s artifacts: From d1d6b1920c791bd8df85f1dc2a3e8dd263a52d34 Mon Sep 17 00:00:00 2001 From: ShellMonster Date: Fri, 20 Nov 2026 17:26:19 +0800 Subject: [PATCH 4/4] fix: preserve playback position after scrubbing --- .github/workflows/windows-e2e.yml | 2 ++ internal/app/app.go | 14 ++++++-------- internal/app/playback_state.go | 26 ++++++++++---------------- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/.github/workflows/windows-e2e.yml b/.github/workflows/windows-e2e.yml index afccaf25..637a0536 100644 --- a/.github/workflows/windows-e2e.yml +++ b/.github/workflows/windows-e2e.yml @@ -24,6 +24,7 @@ on: pull_request: paths: - "internal/e2e/**" + - "internal/app/**" - "internal/ui/**" - "internal/platform/**" # 解码器在这里:AAC/M4A(mfadec)、FLAC(flacdec)、MP3(mp3dec)、 @@ -43,6 +44,7 @@ on: - "work/**" paths: - "internal/e2e/**" + - "internal/app/**" - "internal/ui/**" - "internal/platform/**" - "internal/service/**" diff --git a/internal/app/app.go b/internal/app/app.go index f81b4dca..307c580a 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -347,6 +347,7 @@ type App struct { // playbackDirty 是「播放状态变了,该落盘了」。见 playback_state.go。 playbackDirty bool + scrubRevision uint64 // playbackSavedAt 是上一次落盘的时刻,playbackSavedPos 是那一次的位置。 // // 两者是用来**限速**的:位置一直在变(在放的时候每一拍都在变),而不限速 @@ -1942,6 +1943,8 @@ func (a *App) ScrubEnd(fraction float64) { // 立刻把位置改过来:暂停状态下 tick 不跑,界面下一帧读的就是这里写的值。 a.mu.Lock() a.setPositionLocked(t) + a.scrubRevision++ + a.playbackDirty = true a.playing = p.Playing() // 用户动过时间线了,「停到开头」这件事就过去了。系统那边跟着回到 // playing / paused——它看到的进度条此刻在 t 上,状态却说「停在开头」, @@ -1950,11 +1953,6 @@ func (a *App) ScrubEnd(fraction float64) { wake := a.wake a.mu.Unlock() a.kickTick() - // 用户拖了进度条 → 落盘那一格该跟着变(见 playback_state.go)。 - // - // ⚠️ **这一格算「用户动了一下」**:它走的是那条「尽快写、但至少隔半秒」的 - // 路(见 savePlaybackIfDue),所以拖完不用等 5 秒那个窗口。 - a.markPlaybackDirty() // 锁屏上那根进度条和界面上这根是同一根:不报的话它在原地漂着, // 直到下一次校正(mediaPublishEvery)才跟上。 a.publishMedia() @@ -2213,6 +2211,7 @@ func (a *App) tick() { p := a.player live := a.wantPlay || a.playing dur := a.duration + scrubRevision := a.scrubRevision wake := a.wake a.mu.Unlock() @@ -2244,9 +2243,8 @@ func (a *App) tick() { // ⚠️ 它要认准「是这一台播放器」:换歌时锁里就把 `a.player` 换成 // 新的了,拿旧那台的「不在放」去判新歌放完了,是白报一次。 ended := false - // 位置和 playing 是**这一台播放器**的:这中间换歌了(换歌在锁里把 - // `a.player` 换成新的),就不能把旧那台的位置写到新歌头上。 - if p != nil && live && a.player == p { + // 换歌或拖动进度后,这一拍读到的位置和播放状态已经过期。 + if p != nil && live && a.player == p && a.scrubRevision == scrubRevision { ended = a.playing && !playing if finished { // ⚠️ **放完了就把位置报成 0**:这一串放完了之后进度条该 diff --git a/internal/app/playback_state.go b/internal/app/playback_state.go index 14b5b660..02d0cb66 100644 --- a/internal/app/playback_state.go +++ b/internal/app/playback_state.go @@ -326,8 +326,8 @@ func (a *App) persistPlayback() { return } - snap, pos := a.playbackSnapshot() a.mu.Lock() + pos := a.position a.playbackDirty = false a.playbackSavedAt = time.Now() // ⚠️ **存的是那个精确的纳秒位置**,不是落盘那个毫秒值:这一格是拿来跟 @@ -335,6 +335,7 @@ func (a *App) persistPlayback() { a.playbackSavedPos = pos a.mu.Unlock() + snap := a.playbackSnapshot(pos) if _, err := a.UpdateSettings(func(s *Settings) { s.Playback = snap }); err != nil { // 存不住不算错(理由同 `rememberPlayMode`):设置层自己有入口能看到 // 「这次改的设置存不住」(见 App.TakeSettingsError),在这儿拦一次只会 @@ -357,28 +358,21 @@ func (a *App) SavePlayback() { // playbackSnapshot 拼出现在的队列、当前项和位置。 // -// 第二个返回值是**那个精确的纳秒位置**:落盘那一格是毫秒(那是给文件看的), -// 而落盘那一格的判据要拿它跟 `a.position` 比(见 savePlaybackIfDue)——单位 -// 不一样的话永远不相等。 -// // ⚠️ **当前项存的是标识,不是下标**(见 PlaybackSnapshot.Current)。 -func (a *App) playbackSnapshot() (PlaybackSnapshot, time.Duration) { - a.mu.Lock() - pos := a.position - a.mu.Unlock() - - items := a.queue.Items() +func (a *App) playbackSnapshot(pos time.Duration) PlaybackSnapshot { + queue := a.queue.Snapshot() out := PlaybackSnapshot{ - Items: make([]PlaybackEntry, 0, len(items)), + Items: make([]PlaybackEntry, 0, queue.Len()), Position: pos.Milliseconds(), } - for _, it := range items { + for index := range queue.Len() { + it, _ := queue.At(index) out.Items = append(out.Items, playbackEntryOf(it)) } - if cur, ok := a.queue.Current(); ok { - out.Current = cur.Identity() + if current, ok := queue.At(queue.CurrentIndex()); ok { + out.Current = current.Identity() } - return out, pos + return out } // ---- 恢复 ----