|
|
@@ -2,6 +2,7 @@ import TitleBar from './TitleBar'
|
|
|
import { curves, display, PiPWindow, promptAction, router, SymbolGlyphModifier, window } from '@kit.ArkUI';
|
|
|
import { VideoItem } from '../viewmodel/VideoItem';
|
|
|
import { LengthMetrics, SegmentButton,borderRadiuses, SegmentButtonOptions } from '@kit.ArkUI';
|
|
|
+import { getWebdavVideoItems, getWebdavCurrentPlayIndex, clearWebdavVideoItems } from '../pages/WebDavMainPage';
|
|
|
import {
|
|
|
AppUtil,
|
|
|
ArrayUtil,
|
|
|
@@ -114,6 +115,7 @@ interface PlaylistEventData {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
const DEFAULT_INDEX =
|
|
|
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
|
|
'X', 'Y', 'Z']
|
|
|
@@ -179,6 +181,8 @@ export struct LocalMusic {
|
|
|
@State isRefreshing: boolean = false;
|
|
|
@State maxRefreshingHeight: number = 100.0;
|
|
|
private contentNode?: ComponentContent<Object> = undefined;
|
|
|
+
|
|
|
+ // WebDAV相关实例变量(现在改为从内存读取,不再需要存储)
|
|
|
@State ratioL: number = 1;
|
|
|
@State mediaKuCount: number = 0;
|
|
|
@State albumCount: number = 0;
|
|
|
@@ -659,10 +663,7 @@ export struct LocalMusic {
|
|
|
|
|
|
// 监听歌单播放请求事件
|
|
|
let eventPlaylistPlay: emitter.InnerEvent = { eventId: EventConstants.EVENT_PLAYLIST_PLAY }
|
|
|
- emitter.on(eventPlaylistPlay, (eventData: emitter.EventData) => {
|
|
|
- Logger.info('heanup eventPlaylistPlay received - full eventData: ' + JSON.stringify(eventData))
|
|
|
- Logger.info('heanup eventPlaylistPlay received - eventData.data: ' + JSON.stringify(eventData.data))
|
|
|
-
|
|
|
+ emitter.on(eventPlaylistPlay, async (eventData: emitter.EventData) => {
|
|
|
const data = eventData.data as Record<string, Object>
|
|
|
|
|
|
if (!data) {
|
|
|
@@ -672,11 +673,6 @@ export struct LocalMusic {
|
|
|
|
|
|
// 检查歌单播放数据结构
|
|
|
if (data.playlistId && data.songFilePaths && data.startIndex !== undefined) {
|
|
|
- Logger.info('heanup eventPlaylistPlay: 接收到歌单播放数据')
|
|
|
-
|
|
|
- // 不再提取WebDAV认证信息,直接使用videoItems中的webdav_account_id
|
|
|
-
|
|
|
- // 手动构建数据对象以避免类型转换问题
|
|
|
const playlistData: PlaylistEventData = {
|
|
|
playlistId: data.playlistId as string,
|
|
|
playlistName: data.playlistName as string,
|
|
|
@@ -684,8 +680,8 @@ export struct LocalMusic {
|
|
|
startIndex: data.startIndex as number,
|
|
|
songFilePaths: data.songFilePaths as string[]
|
|
|
}
|
|
|
- // 根据文件路径重新构建歌曲列表,不再传递WebDAV认证信息
|
|
|
- this.handlePlaylistPlayRequest(
|
|
|
+
|
|
|
+ await this.handlePlaylistPlayRequest(
|
|
|
playlistData.playlistId,
|
|
|
playlistData.playlistName,
|
|
|
playlistData.songFilePaths,
|
|
|
@@ -13373,68 +13369,29 @@ export struct LocalMusic {
|
|
|
/**
|
|
|
* 处理歌单播放请求
|
|
|
*/
|
|
|
- private handlePlaylistPlayRequest(playlistId: string, playlistName:
|
|
|
+ private async handlePlaylistPlayRequest(playlistId: string, playlistName:
|
|
|
string, songFilePaths: string[], startIndex: number) {
|
|
|
try {
|
|
|
Logger.info(`heanup 处理歌单播放请求: ${playlistName}, 歌曲数量: ${songFilePaths.length}, 开始索引: ${startIndex}`)
|
|
|
|
|
|
// 检查是否为WebDAV播放请求
|
|
|
if (playlistId === 'webdav-playlist') {
|
|
|
- Logger.info(`heanup 检测到WebDAV播放请求,直接使用videoItems中的webdav_account_id进行认证`)
|
|
|
+ Logger.info(`heanup 检测到WebDAV播放请求,从内存读取videoItems`)
|
|
|
|
|
|
- // 尝试从全局上下文获取videoItems(如果WebDavMainPage已经保存了的话)
|
|
|
- const globalContext = GlobalContext.getContext();
|
|
|
- const videoItems = globalContext.getObject('videoItems') as VideoItem[];
|
|
|
- const currentPlayIndex = globalContext.getObject('currentPlayIndex') as number;
|
|
|
+ // 从全局内存读取videoItems数据
|
|
|
+ const videoItems = getWebdavVideoItems();
|
|
|
+ const currentPlayIndex = getWebdavCurrentPlayIndex();
|
|
|
|
|
|
- Logger.info(`heanup 从GlobalContext获取数据: videoItems长度=${videoItems?.length || 0}, currentPlayIndex=${currentPlayIndex}`);
|
|
|
+ Logger.info(`heanup 从内存读取到WebDAV歌曲列表,长度:${videoItems.length},索引:${currentPlayIndex}`)
|
|
|
|
|
|
- // 检查videoItems中的webdav_account_id设置情况
|
|
|
if (videoItems && videoItems.length > 0) {
|
|
|
+ // 验证webdav_account_id设置情况
|
|
|
const accountIds = videoItems.map(item => item.webdav_account_id).filter(id => id);
|
|
|
- Logger.info(`heanup videoItems中有 ${accountIds.length}/${videoItems.length} 首歌曲设置了webdav_account_id`);
|
|
|
+ Logger.info(`heanup 有 ${accountIds.length}/${videoItems.length} 首歌曲设置了webdav_account_id`)
|
|
|
|
|
|
- // 显示前几首歌曲的webdav_account_id状态
|
|
|
- for (let i = 0; i < Math.min(3, videoItems.length); i++) {
|
|
|
- const item = videoItems[i];
|
|
|
- Logger.info(`heanup 歌曲[${i}]: ${item?.name}, webdav_account_id: ${item?.webdav_account_id || '未设置'}`);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (videoItems && videoItems.length > 0) {
|
|
|
- Logger.info(`heanup 从全局上下文获取到WebDAV歌曲列表,长度:${videoItems.length}`)
|
|
|
- // 验证歌曲数据是否完整
|
|
|
- for (let i = 0; i < Math.min(3, videoItems.length); i++) {
|
|
|
- Logger.info(`heanup 歌曲[${i}]: ${videoItems[i]?.name}, 路径: ${videoItems[i]?.filePath}`)
|
|
|
- }
|
|
|
- this.finishLoadingPlaylist(videoItems, startIndex, playlistName)
|
|
|
+ this.finishLoadingPlaylist(videoItems, currentPlayIndex, playlistName)
|
|
|
return
|
|
|
} else {
|
|
|
- Logger.error(`heanup 无法从全局上下文获取WebDAV歌曲数据,尝试使用传入的文件路径创建备用数据`)
|
|
|
-
|
|
|
- // 备用方案:直接使用传入的文件路径创建VideoItem
|
|
|
- const fallbackVideoItems: VideoItem[] = [];
|
|
|
- for (let i = 0; i < songFilePaths.length; i++) {
|
|
|
- const fileName = songFilePaths[i].split('/').pop() || `WebDAV歌曲${i+1}`;
|
|
|
- const videoItem = new VideoItem(
|
|
|
- fileName.replace(/\.(flac|mp3|wav|m4a)$/i, ''), // name (去掉扩展名)
|
|
|
- '', // id
|
|
|
- songFilePaths[i], // filePath (URL)
|
|
|
- CommonConstants.TYPE_WEBDAV, // type
|
|
|
- 0, // videoSize
|
|
|
- "0", // cTime
|
|
|
- undefined, // pixelMap
|
|
|
- undefined, // size
|
|
|
- undefined, // pixelMapPath
|
|
|
- "WebDAV", // artist
|
|
|
- undefined, // album
|
|
|
- fileName // fileName
|
|
|
- );
|
|
|
- fallbackVideoItems.push(videoItem);
|
|
|
- }
|
|
|
-
|
|
|
- Logger.info(`heanup 使用备用方案创建了${fallbackVideoItems.length}首WebDAV歌曲`)
|
|
|
- this.finishLoadingPlaylist(fallbackVideoItems, startIndex, playlistName)
|
|
|
return
|
|
|
}
|
|
|
}
|