|
|
@@ -94,9 +94,9 @@ import { showCreatePlaylistDialog } from '../dialog/PlaylistDialog';
|
|
|
const TAG = 'LocalMusic';
|
|
|
|
|
|
/**
|
|
|
- * 简化的歌单播放事件数据
|
|
|
+ * 歌单播放事件数据
|
|
|
*/
|
|
|
-interface SimplifiedPlaylistEventData {
|
|
|
+interface PlaylistEventData {
|
|
|
playlistId: string;
|
|
|
playlistName: string;
|
|
|
songCount: number;
|
|
|
@@ -583,11 +583,11 @@ export struct LocalMusic {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 检查简化数据结构
|
|
|
+ // 检查歌单播放数据结构
|
|
|
if (data.playlistId && data.songFilePaths && data.startIndex !== undefined) {
|
|
|
- Logger.info('heanup eventPlaylistPlay: received simplified playlist data')
|
|
|
- // 手动构建简化数据对象以避免类型转换问题
|
|
|
- const simplifiedData: SimplifiedPlaylistEventData = {
|
|
|
+ Logger.info('heanup eventPlaylistPlay: 接收到歌单播放数据')
|
|
|
+ // 手动构建数据对象以避免类型转换问题
|
|
|
+ const playlistData: PlaylistEventData = {
|
|
|
playlistId: data.playlistId as string,
|
|
|
playlistName: data.playlistName as string,
|
|
|
songCount: data.songCount as number,
|
|
|
@@ -595,23 +595,16 @@ export struct LocalMusic {
|
|
|
songFilePaths: data.songFilePaths as string[]
|
|
|
}
|
|
|
// 根据文件路径重新构建歌曲列表
|
|
|
- this.handleSimplifiedPlaylistPlayRequest(
|
|
|
- simplifiedData.playlistId,
|
|
|
- simplifiedData.playlistName,
|
|
|
- simplifiedData.songFilePaths,
|
|
|
- simplifiedData.startIndex
|
|
|
+ this.handlePlaylistPlayRequest(
|
|
|
+ playlistData.playlistId,
|
|
|
+ playlistData.playlistName,
|
|
|
+ playlistData.songFilePaths,
|
|
|
+ playlistData.startIndex
|
|
|
)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 检查原始数据结构(向后兼容)
|
|
|
- if (data.playlist && data.songs && data.startIndex !== undefined) {
|
|
|
- Logger.info('heanup eventPlaylistPlay: received original playlist data')
|
|
|
- this.handlePlaylistPlayRequest(data.playlist as Playlist, data.songs as VideoItem[], data.startIndex as number)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- Logger.error('heanup eventPlaylistPlay: invalid data structure received')
|
|
|
+ Logger.error('heanup eventPlaylistPlay: 接收到无效的数据结构')
|
|
|
});
|
|
|
|
|
|
let eventSetting: emitter.InnerEvent = { eventId: EventConstants.EVENT_SETTING_UPDATE }
|
|
|
@@ -13022,35 +13015,9 @@ export struct LocalMusic {
|
|
|
/**
|
|
|
* 处理歌单播放请求
|
|
|
*/
|
|
|
- private handlePlaylistPlayRequest(playlist: Playlist, songs: VideoItem[], startIndex: number) {
|
|
|
- try {
|
|
|
- // 1. 替换当前播放列表
|
|
|
- this.songList = songs
|
|
|
- this.sonDataSource.pushArrayData(songs)
|
|
|
-
|
|
|
- // 2. 设置当前播放索引
|
|
|
- this.curIndex = startIndex
|
|
|
-
|
|
|
- // 3. 播放指定歌曲
|
|
|
- if (songs[startIndex]) {
|
|
|
- this.doPlay(songs[startIndex], startIndex)
|
|
|
- }
|
|
|
-
|
|
|
- // 4. 保存播放列表
|
|
|
- PreferencesUtil.putSync('LastMusicList', this.songList)
|
|
|
-
|
|
|
- console.info(`heanup 开始播放歌单: ${playlist.name}, 歌曲数量: ${songs.length}, 开始索引: ${startIndex}`)
|
|
|
- } catch (error) {
|
|
|
- console.error('heanup 处理歌单播放请求失败:', error)
|
|
|
- ToastUtil.showToast('播放失败')
|
|
|
- }
|
|
|
-}
|
|
|
- /**
|
|
|
- * 处理简化的歌单播放请求
|
|
|
- */
|
|
|
- private handleSimplifiedPlaylistPlayRequest(playlistId: string, playlistName: string, songFilePaths: string[], startIndex: number) {
|
|
|
+ private handlePlaylistPlayRequest(playlistId: string, playlistName: string, songFilePaths: string[], startIndex: number) {
|
|
|
try {
|
|
|
- Logger.info(`heanup 处理简化歌单播放请求: ${playlistName}, 歌曲数量: ${songFilePaths.length}, 开始索引: ${startIndex}`)
|
|
|
+ Logger.info(`heanup 处理歌单播放请求: ${playlistName}, 歌曲数量: ${songFilePaths.length}, 开始索引: ${startIndex}`)
|
|
|
|
|
|
// 从数据库重新加载这些歌曲,使用索引记录位置以保持顺序
|
|
|
const songMap: Map<number, VideoItem> = new Map()
|
|
|
@@ -13133,40 +13100,21 @@ export struct LocalMusic {
|
|
|
ToastUtil.showToast('没有找到可播放的歌曲')
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- Logger.info(`heanup 找到 ${songs.length} 首可播放的歌曲`)
|
|
|
-
|
|
|
- // 1. 替换当前播放列表并更新存储
|
|
|
- Logger.info(`heanup 更新前 - 当前播放列表长度: ${this.songList.length}`)
|
|
|
this.songList = songs
|
|
|
- // 确保存储也更新(@StorageLink会自动同步)
|
|
|
- Logger.info(`heanup 更新后 - 新播放列表长度: ${this.songList.length}`)
|
|
|
|
|
|
- // 2. 更新数据源
|
|
|
- Logger.info(`heanup 更新前 - 数据源长度: ${this.sonDataSource.totalCount()}`)
|
|
|
this.sonDataSource.pushArrayData(songs)
|
|
|
- Logger.info(`heanup 更新后 - 数据源长度: ${this.sonDataSource.totalCount()}`)
|
|
|
|
|
|
- // 3. 强制触发UI重新渲染
|
|
|
- Logger.info('heanup 触发UI重新渲染')
|
|
|
this.sonDataSource.notifyDataReload()
|
|
|
|
|
|
- // 4. 设置当前播放索引
|
|
|
this.curIndex = startIndex
|
|
|
|
|
|
- // 5. 播放指定歌曲
|
|
|
if (songs[startIndex]) {
|
|
|
- Logger.info(`heanup 开始播放歌曲: ${songs[startIndex].name}, 索引: ${startIndex}`)
|
|
|
- Logger.info(`heanup 播放前 - 播放列表长度: ${this.songList.length}, 当前索引: ${this.curIndex}`)
|
|
|
// 确保当前播放的歌曲也更新到存储
|
|
|
AppStorage.setOrCreate('currentSong', songs[startIndex])
|
|
|
// 设置isFromSonPlayList=true,避免doPlay方法重新从全局列表构建播放列表
|
|
|
- Logger.info(`heanup 调用doPlay,参数: 歌曲=${songs[startIndex].name}, 索引=${startIndex}, isFromSonPlayList=true`)
|
|
|
this.doPlay(songs[startIndex], startIndex, true)
|
|
|
- Logger.info(`heanup doPlay调用完成`)
|
|
|
}
|
|
|
|
|
|
- // 5. 保存播放列表
|
|
|
PreferencesUtil.putSync('LastMusicList', this.songList)
|
|
|
|
|
|
ToastUtil.showToast(`开始播放歌单: ${playlistName}`)
|