|
|
@@ -13051,41 +13051,68 @@ export struct LocalMusic {
|
|
|
try {
|
|
|
Logger.info(`heanup 处理简化歌单播放请求: ${playlistName}, 歌曲数量: ${songFilePaths.length}, 开始索引: ${startIndex}`)
|
|
|
|
|
|
- // 从数据库重新加载这些歌曲
|
|
|
- const songs: VideoItem[] = []
|
|
|
+ // 从数据库重新加载这些歌曲,使用索引记录位置以保持顺序
|
|
|
+ const songMap: Map<number, VideoItem> = new Map()
|
|
|
let completedQueries = 0
|
|
|
|
|
|
Logger.info(`heanup 开始从数据库查询 ${songFilePaths.length} 首歌曲`)
|
|
|
|
|
|
- for (const filePath of songFilePaths) {
|
|
|
- Logger.info(`heanup 正在查询歌曲: ${filePath}`)
|
|
|
+ // 遍历所有文件路径,使用索引记录位置
|
|
|
+ for (let i = 0; i < songFilePaths.length; i++) {
|
|
|
+ const filePath = songFilePaths[i]
|
|
|
+ const index = i
|
|
|
+ Logger.info(`heanup 正在查询歌曲[${index}]: ${filePath}`)
|
|
|
+
|
|
|
// 使用已初始化的MediaTable实例从数据库查询歌曲信息
|
|
|
const queryPromise = this.table.queryVideoByFilePath(filePath)
|
|
|
- Logger.info(`heanup 创建了查询Promise,开始等待结果: ${filePath}`)
|
|
|
+ Logger.info(`heanup 创建了查询Promise,开始等待结果[${index}]: ${filePath}`)
|
|
|
|
|
|
queryPromise.then((videoItem) => {
|
|
|
completedQueries++
|
|
|
- Logger.info(`heanup 查询Promise返回结果: ${filePath}, 找到歌曲: ${videoItem ? videoItem.name : 'null'}`)
|
|
|
+ Logger.info(`heanup 查询Promise返回结果[${index}]: ${filePath}, 找到歌曲: ${videoItem ? videoItem.name : 'null'}`)
|
|
|
|
|
|
if (videoItem) {
|
|
|
- songs.push(videoItem)
|
|
|
- Logger.info(`heanup 从数据库找到歌曲: ${videoItem.name} (${completedQueries}/${songFilePaths.length})`)
|
|
|
+ // 使用索引作为key保存到Map中,保持原始顺序
|
|
|
+ songMap.set(index, videoItem)
|
|
|
+ Logger.info(`heanup 从数据库找到歌曲[${index}]: ${videoItem.name} (${completedQueries}/${songFilePaths.length})`)
|
|
|
} else {
|
|
|
- Logger.warn(`heanup 数据库中未找到歌曲: ${filePath} (${completedQueries}/${songFilePaths.length})`)
|
|
|
+ Logger.warn(`heanup 数据库中未找到歌曲[${index}]: ${filePath} (${completedQueries}/${songFilePaths.length})`)
|
|
|
}
|
|
|
|
|
|
// 检查是否所有歌曲都已加载完成
|
|
|
if (completedQueries === songFilePaths.length) {
|
|
|
- Logger.info(`heanup 所有数据库查询完成,共找到 ${songs.length} 首歌曲`)
|
|
|
+ Logger.info(`heanup 所有数据库查询完成,共找到 ${songMap.size} 首歌曲`)
|
|
|
+
|
|
|
+ // 按照索引顺序重建歌曲数组
|
|
|
+ const songs: VideoItem[] = []
|
|
|
+ for (let j = 0; j < songFilePaths.length; j++) {
|
|
|
+ const song = songMap.get(j)
|
|
|
+ if (song) {
|
|
|
+ songs.push(song)
|
|
|
+ Logger.info(`heanup 按顺序添加歌曲[${j}]: ${song.name}`)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Logger.info(`heanup 最终歌曲列表顺序: ${songs.map((s, idx) => `[${idx}]${s.name}`).join(', ')}`)
|
|
|
this.finishLoadingPlaylist(songs, startIndex, playlistName)
|
|
|
}
|
|
|
}).catch((error: Error) => {
|
|
|
completedQueries++
|
|
|
- Logger.error(`heanup 查询歌曲失败: ${filePath}, 错误: ${error.message} (${completedQueries}/${songFilePaths.length})`)
|
|
|
+ Logger.error(`heanup 查询歌曲失败[${index}]: ${filePath}, 错误: ${error.message} (${completedQueries}/${songFilePaths.length})`)
|
|
|
|
|
|
// 即使出错也要检查是否完成所有查询
|
|
|
if (completedQueries === songFilePaths.length) {
|
|
|
- Logger.info(`heanup 所有数据库查询完成(包含错误),共找到 ${songs.length} 首歌曲`)
|
|
|
+ Logger.info(`heanup 所有数据库查询完成(包含错误),共找到 ${songMap.size} 首歌曲`)
|
|
|
+
|
|
|
+ // 按照索引顺序重建歌曲数组
|
|
|
+ const songs: VideoItem[] = []
|
|
|
+ for (let j = 0; j < songFilePaths.length; j++) {
|
|
|
+ const song = songMap.get(j)
|
|
|
+ if (song) {
|
|
|
+ songs.push(song)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
this.finishLoadingPlaylist(songs, startIndex, playlistName)
|
|
|
}
|
|
|
})
|