Skip to content

Commit 70ab357

Browse files
authored
fix: 随机模式下当前播放歌曲于列表中的位置出现错误和不同步的情况 (#2378)
* fix(Player.js): 随机模式下列表初始化时当前歌曲的下标异常 异常情况:假设歌曲A其在歌单中的位置为10,随机模式下双击该歌曲后,this.current != 10 原因:随机模式下,通过 indexOf 计算 current 时,调用的数组与真实的列表数组不一致 * fix(Player.js): 随机模式切换时未同步当前歌曲下标 * fix: 随机播放顺序与实际列表不一致 使用 filter 不保证返回的数组的元素顺序与传入的id 顺序对应
1 parent c7e6915 commit 70ab357

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/utils/Player.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ export default class {
130130
if (shuffle) {
131131
this._shuffleTheList();
132132
}
133+
// 同步当前歌曲在列表中的下标
134+
this.current = this.list.indexOf(this.currentTrackID);
133135
}
134136
get reversed() {
135137
return this._reversed;
@@ -892,7 +894,7 @@ export default class {
892894
if (autoPlayTrackID === 'first') {
893895
this._replaceCurrentTrack(this.list[0]);
894896
} else {
895-
this.current = trackIDs.indexOf(autoPlayTrackID);
897+
this.current = this.list.indexOf(autoPlayTrackID);
896898
this._replaceCurrentTrack(autoPlayTrackID);
897899
}
898900
}

src/views/next.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ export default {
5757
this.player.current + 1,
5858
this.player.current + 100
5959
);
60-
return this.tracks.filter(t => trackIDs.includes(t.id));
60+
return trackIDs
61+
.map(tid => this.tracks.find(t => t.id === tid))
62+
.filter(t => t);
6163
},
6264
playNextList() {
6365
return this.player.playNextList;

0 commit comments

Comments
 (0)