|
|
@@ -70,18 +70,21 @@ export struct PlaylistDetailPage {
|
|
|
async loadPlaylistDetail() {
|
|
|
try {
|
|
|
this.isLoading = true
|
|
|
-
|
|
|
+
|
|
|
if (!this.playlist) {
|
|
|
ToastUtil.showToast('歌单不存在')
|
|
|
router.back()
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 加载歌单歌曲
|
|
|
const playlistSongs = await this.playlistTable.queryPlaylistSongs(this.playlistId)
|
|
|
-
|
|
|
+
|
|
|
// 将 PlaylistSong 转换为 VideoItem
|
|
|
this.songList = await this.convertPlaylistSongsToVideoItems(playlistSongs)
|
|
|
+
|
|
|
+ // 歌单加载完成后,加载当前播放状态
|
|
|
+ this.loadCurrentPlaybackStatus()
|
|
|
} catch (error) {
|
|
|
LogUtil.error('heanup 加载歌单详情失败: ' + error)
|
|
|
ToastUtil.showToast('加载歌单详情失败')
|
|
|
@@ -165,24 +168,29 @@ export struct PlaylistDetailPage {
|
|
|
const data = eventData.data as Record<string, Object>
|
|
|
const oldIsPlaying = this.isPlaying
|
|
|
const oldCurIndex = this.curIndex
|
|
|
-
|
|
|
- // 添加调试日志
|
|
|
|
|
|
this.isPlaying = data['isPlaying'] as boolean
|
|
|
- let newCurIndex = data['curIndex'] as number
|
|
|
-
|
|
|
- LogUtil.info(`heanup 原始播放状态: isPlaying=${this.isPlaying}, curIndex=${newCurIndex}`)
|
|
|
+ const currentFilePath = data['currentFilePath'] as string
|
|
|
|
|
|
-
|
|
|
- this.curIndex = newCurIndex
|
|
|
+ LogUtil.info(`heanup 原始播放状态: isPlaying=${this.isPlaying}, currentFilePath=${currentFilePath}`)
|
|
|
|
|
|
- LogUtil.info(`heanup 播放状态更新: isPlaying=${oldIsPlaying}->${this.isPlaying}, curIndex=${oldCurIndex}->${this.curIndex}`)
|
|
|
-
|
|
|
- // 检查当前播放的歌曲是否在当前歌单中
|
|
|
- if (this.curIndex >= 0 && this.curIndex < this.songList.length) {
|
|
|
- const currentSong = this.songList[this.curIndex]
|
|
|
- LogUtil.info(`heanup 当前播放歌曲: ${currentSong.name}, 文件路径: ${currentSong.filePath}`)
|
|
|
+ // 通过filePath在当前歌单中查找对应的索引
|
|
|
+ if (currentFilePath) {
|
|
|
+ const matchedIndex = this.songList.findIndex(song => song.filePath === currentFilePath)
|
|
|
+ if (matchedIndex !== -1) {
|
|
|
+ this.curIndex = matchedIndex
|
|
|
+ LogUtil.info(`heanup 在歌单中找到匹配的歌曲: ${this.songList[matchedIndex].name}, 索引: ${matchedIndex}`)
|
|
|
+ } else {
|
|
|
+ // 当前播放的歌曲不在本歌单中,重置索引
|
|
|
+ this.curIndex = -1
|
|
|
+ LogUtil.info(`heanup 当前播放的歌曲不在本歌单中: ${currentFilePath}`)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.curIndex = -1
|
|
|
+ LogUtil.info(`heanup 当前没有播放歌曲`)
|
|
|
}
|
|
|
+
|
|
|
+ LogUtil.info(`heanup 播放状态更新: isPlaying=${oldIsPlaying}->${this.isPlaying}, curIndex=${oldCurIndex}->${this.curIndex}`)
|
|
|
}
|
|
|
})
|
|
|
} catch (error) {
|
|
|
@@ -201,6 +209,34 @@ export struct PlaylistDetailPage {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 加载当前播放状态
|
|
|
+ */
|
|
|
+ loadCurrentPlaybackStatus() {
|
|
|
+ try {
|
|
|
+ // 从AppStorage获取当前播放的歌曲
|
|
|
+ const currentSong = AppStorage.get<VideoItem>('currentSong')
|
|
|
+ if (currentSong && currentSong.filePath) {
|
|
|
+ LogUtil.info(`heanup 获取到当前播放歌曲: ${currentSong.name}, filePath: ${currentSong.filePath}`)
|
|
|
+
|
|
|
+ // 在歌单中查找匹配的歌曲
|
|
|
+ const matchedIndex = this.songList.findIndex(song => song.filePath === currentSong.filePath)
|
|
|
+ if (matchedIndex !== -1) {
|
|
|
+ this.curIndex = matchedIndex
|
|
|
+ // 假设如果有currentSong说明正在播放
|
|
|
+ this.isPlaying = true
|
|
|
+ LogUtil.info(`heanup 在歌单中找到当前播放的歌曲: ${this.songList[matchedIndex].name}, 索引: ${matchedIndex}`)
|
|
|
+ } else {
|
|
|
+ LogUtil.info(`heanup 当前播放的歌曲不在本歌单中`)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ LogUtil.info(`heanup 当前没有播放歌曲`)
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ LogUtil.error('heanup 加载当前播放状态失败: ' + error)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 将 PlaylistSong 转换为 VideoItem
|
|
|
*/
|