|
|
@@ -14,7 +14,7 @@ import { LazyDataSource } from '../common/util/LazyDataSource';
|
|
|
import { ConfigurationConstant } from '@kit.AbilityKit';
|
|
|
import { ButtonFancyModifier, ShadowModifier, SymbolGlyphFancyModifier } from '../common/util/AttributeModifierUtil';
|
|
|
import { PlayingIndicator } from '../view/PlayingIndicator';
|
|
|
-import { PlaylistPlayRequest, savePendingPlaylistPlay } from '../common/util/PlaylistPlayRequestStore';
|
|
|
+import { MusicPlaybackController } from '../controller/MusicPlaybackController';
|
|
|
|
|
|
// 工具函数:将 #RRGGBB 字符串和透明度转为 'rgba(r,g,b,a)' 字符串,深色模式下可返回深色变体
|
|
|
function themeColorWithAlpha(themeColor: string, alpha: number, isDarkMode: boolean = false): string {
|
|
|
@@ -52,6 +52,7 @@ export struct PlaylistDetailPage {
|
|
|
|
|
|
private playlistTable: PlaylistTable = new PlaylistTable(getContext(this))
|
|
|
private mediaTable: MediaTable = new MediaTable(getContext(this))
|
|
|
+ private playbackController: MusicPlaybackController = MusicPlaybackController.getInstance()
|
|
|
private playlistId: string = ''
|
|
|
@StorageProp('themeColor') themeColor: string = CommonConstants.DEFAULT_THEME_COLOR;
|
|
|
@State isDarkMode: boolean = false
|
|
|
@@ -406,31 +407,13 @@ export struct PlaylistDetailPage {
|
|
|
ToastUtil.showToast('歌单为空')
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- // 发送播放歌单事件
|
|
|
- const eventPlaylistPlay: emitter.InnerEvent = { eventId: EventConstants.EVENT_PLAYLIST_PLAY }
|
|
|
-
|
|
|
- LogUtil.info(`heanup 准备发送播放事件,playlist: ${this.playlist ? '存在' : '不存在'}, songs: ${this.songList.length}首`)
|
|
|
-
|
|
|
- // 构建歌单播放事件数据
|
|
|
- const playlistData = new PlaylistPlayRequest(
|
|
|
- this.playlist?.id || '',
|
|
|
- this.playlist?.name || '',
|
|
|
- this.songList.length,
|
|
|
- 0,
|
|
|
- this.songList.map(song => song.filePath)
|
|
|
- );
|
|
|
-
|
|
|
- LogUtil.info(`heanup 发送歌单播放事件数据: ${JSON.stringify(playlistData)}`)
|
|
|
-
|
|
|
- const eventData: emitter.EventData = {
|
|
|
- data: playlistData
|
|
|
- };
|
|
|
-
|
|
|
- savePendingPlaylistPlay(playlistData)
|
|
|
- emitter.emit(eventPlaylistPlay, eventData)
|
|
|
-
|
|
|
- ToastUtil.showToast('开始播放歌单')
|
|
|
+ LogUtil.info(`heanup 直连播放歌单,playlist: ${this.playlist ? '存在' : '不存在'}, songs: ${this.songList.length}首`)
|
|
|
+ void this.playbackController.playQueue([...this.songList], 0, 'controller-open').then(() => {
|
|
|
+ ToastUtil.showToast('开始播放歌单')
|
|
|
+ }).catch((error: Error) => {
|
|
|
+ LogUtil.error(`heanup 播放歌单失败: ${error}`)
|
|
|
+ ToastUtil.showToast('播放失败')
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -441,30 +424,11 @@ export struct PlaylistDetailPage {
|
|
|
LogUtil.info(`heanup 播放指定歌曲: ${song.name}, 索引: ${index}`)
|
|
|
LogUtil.info(`heanup 歌曲列表长度: ${this.songList.length}`)
|
|
|
LogUtil.info(`heanup 歌单ID: ${this.playlist?.id}, 歌单名称: ${this.playlist?.name}`)
|
|
|
-
|
|
|
- // 检查歌曲文件路径
|
|
|
LogUtil.info(`heanup 所有歌曲文件路径: ${JSON.stringify(this.songList.map(s => s.filePath))}`)
|
|
|
-
|
|
|
- // 发送播放歌单事件
|
|
|
- const eventPlaylistPlay: emitter.InnerEvent = { eventId: EventConstants.EVENT_PLAYLIST_PLAY }
|
|
|
- const playlistData = new PlaylistPlayRequest(
|
|
|
- this.playlist?.id || '',
|
|
|
- this.playlist?.name || '',
|
|
|
- this.songList.length,
|
|
|
- index,
|
|
|
- this.songList.map(s => s.filePath)
|
|
|
- );
|
|
|
-
|
|
|
- LogUtil.info(`heanup 准备发送事件,eventId: ${eventPlaylistPlay.eventId}`)
|
|
|
- LogUtil.info(`heanup 发送歌单播放事件数据: ${JSON.stringify(playlistData)}`)
|
|
|
-
|
|
|
- const eventData: emitter.EventData = {
|
|
|
- data: playlistData
|
|
|
- };
|
|
|
-
|
|
|
- LogUtil.info(`heanup eventData对象: ${JSON.stringify(eventData)}`)
|
|
|
- savePendingPlaylistPlay(playlistData)
|
|
|
- emitter.emit(eventPlaylistPlay, eventData)
|
|
|
+ void this.playbackController.playQueue([...this.songList], index, 'controller-open').catch((error: Error) => {
|
|
|
+ LogUtil.error(`heanup 播放指定歌曲失败: ${error}`)
|
|
|
+ ToastUtil.showToast('播放失败')
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -562,19 +526,12 @@ export struct PlaylistDetailPage {
|
|
|
}
|
|
|
|
|
|
// 更新播放列表(重新发送歌单播放事件,保持当前播放位置)
|
|
|
- const playlistData = new PlaylistPlayRequest(
|
|
|
- this.playlist.id,
|
|
|
- this.playlist.name,
|
|
|
- this.songList.length,
|
|
|
- this.curIndex >= this.songList.length ? Math.max(0, this.songList.length - 1) : this.curIndex,
|
|
|
- this.songList.map(s => s.filePath)
|
|
|
- )
|
|
|
-
|
|
|
- const eventPlaylistPlay: emitter.InnerEvent = { eventId: EventConstants.EVENT_PLAYLIST_PLAY }
|
|
|
- const eventData: emitter.EventData = { data: playlistData }
|
|
|
- savePendingPlaylistPlay(playlistData)
|
|
|
- emitter.emit(eventPlaylistPlay, eventData)
|
|
|
- LogUtil.info('heanup 已更新播放列表,移除了被删除的歌曲')
|
|
|
+ const nextIndex = this.curIndex >= this.songList.length ? Math.max(0, this.songList.length - 1) : this.curIndex
|
|
|
+ void this.playbackController.playQueue([...this.songList], nextIndex, 'playlist-detail-sync').then(() => {
|
|
|
+ LogUtil.info('heanup 已通过 controller 更新播放列表,移除了被删除的歌曲')
|
|
|
+ }).catch((error: Error) => {
|
|
|
+ LogUtil.error(`heanup 更新播放列表失败: ${error}`)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
ToastUtil.showToast('已从歌单移除')
|
|
|
@@ -1754,4 +1711,3 @@ export async function updateAllSongsSortOrder(playlistTable:PlaylistTable,song
|
|
|
|
|
|
|
|
|
|
|
|
-
|