Răsfoiți Sursa

DialogHelper第三方库更新到最新 的id处理
Navidrome的歌单播放问题

onecold 7 luni în urmă
părinte
comite
3c92da2b17

+ 47 - 3
entry/src/main/ets/common/network/NavidromeRestApi.ets

@@ -101,6 +101,11 @@ export interface NavidromeRestPlaylist {
   evaluatedAt?: string;
 }
 
+// 歌单API返回的歌曲数据,包含mediaFileId字段
+interface NavidromePlaylistSong extends NavidromeRestSong {
+  mediaFileId?: string;
+}
+
 export interface NavidromePagedResponse<T> {
   data: T[];
   nextStart: number | null;
@@ -187,12 +192,51 @@ export class NavidromeRestApi {
         new QueryParam('_order', 'DESC')
       ];
       const path = `/api/playlist/${playlistId}/tracks`;
-      const chunk = await this.get<NavidromeRestSong[]>(account, path, params);
+
+      // 获取原始响应数据,使用NavidromePlaylistSong类型(包含mediaFileId字段)
+      const chunk = await this.get<NavidromePlaylistSong[]>(account, path, params);
       if (!chunk || chunk.length === 0) {
         break;
       }
-      results.push(...chunk);
-      if (chunk.length < this.PAGE_SIZE) {
+
+      // 处理歌单API返回的数据,将mediaFileId映射到id字段
+      const processed: NavidromeRestSong[] = [];
+      for (let i = 0; i < chunk.length; i++) {
+        const item = chunk[i];
+
+        // 如果存在mediaFileId,使用它作为id;否则使用原id
+        const songId = item.mediaFileId && item.mediaFileId.length > 0 ? item.mediaFileId : item.id;
+
+        if (item.mediaFileId && item.mediaFileId.length > 0) {
+          void ServerLogUtil.debug('NavidromePlaylist', `歌单歌曲使用mediaFileId作为id: ${item.mediaFileId}`);
+        }
+
+        const processedItem: NavidromeRestSong = {
+          id: songId,
+          title: item.title,
+          album: item.album,
+          albumId: item.albumId,
+          artist: item.artist,
+          artistId: item.artistId,
+          duration: item.duration,
+          bitRate: item.bitRate,
+          suffix: item.suffix,
+          size: item.size,
+          createdAt: item.createdAt,
+          genre: item.genre,
+          track: item.track,
+          year: item.year,
+          contentType: item.contentType,
+          coverArt: item.coverArt,
+          coverArtId: item.coverArtId,
+          coverArtPath: item.coverArtPath,
+          embedArtPath: item.embedArtPath
+        };
+        processed.push(processedItem);
+      }
+
+      results.push(...processed);
+      if (processed.length < this.PAGE_SIZE) {
         break;
       }
       start = end;

+ 14 - 35
entry/src/main/ets/view/LocalMusic.ets

@@ -1875,22 +1875,11 @@ export struct LocalMusic {
     this.refreshLazyListViews(mainListUpdated, playlistUpdated);
   }
 
-  private closeLoadingDialog(): void {
-    if (!this.loadingDialogId) {
-      return;
-    }
-    DialogHelper.closeDialog(this.loadingDialogId);
-    this.loadingDialogId = '';
-  }
 
-  private closeLoadingProgressDialog(): void {
-    DialogHelper.closeLoading();
-    this.loadingProgressDialogId = '';
-  }
 
   private handleEditMusicResult(result: WorkerEditMusicResult): void {
     // 关闭进度条
-    this.closeLoadingDialog();
+    DialogHelper.closeDialog(this.loadingDialogId)
 
     if (result.success) {
       console.log("heanup 编辑信息成功,数据库已同步");
@@ -2956,14 +2945,13 @@ export struct LocalMusic {
 
     // 初始化进度条
     this.progress  = 0;
-    DialogHelper.showLoadingProgress({
+    this.loadingProgressDialogId =  DialogHelper.showLoadingProgress({
       progress: this.progress,
       backCancel: false,
       autoCancel: false,
       loadColor: $r('app.color.title_bar_bg'),
       fontColor: $r('app.color.title_bar_bg')
     });
-    this.loadingProgressDialogId = '';
 
     // 计算处理总数用于进度计算
     const totalItems = uris.length;
@@ -2991,18 +2979,18 @@ export struct LocalMusic {
         // 更新进度
         processedItems++;
         this.progress  = Math.floor((processedItems  / totalItems) * 100);
-        DialogHelper.updateLoading(` 正在处理 ${this.progress}%`, this.progress);
+        DialogHelper.updateLoading(this.loadingProgressDialogId,` 正在处理 ${this.progress}%`, this.progress);
 
       } catch (error) {
         Logger.error(TAG,  'saveVideoDatas failed with err: ' + JSON.stringify(error));
         // 即使出错也更新进度
         processedItems++;
         this.progress  = Math.floor((processedItems  / totalItems) * 100);
-        DialogHelper.updateLoading(` 正在处理 ${this.progress}%`, this.progress);
+        DialogHelper.updateLoading(this.loadingProgressDialogId,` 正在处理 ${this.progress}%`, this.progress);
       }
     }
     // 关闭进度条
-    this.closeLoadingProgressDialog();
+    DialogHelper.closeDialog(this.loadingProgressDialogId)
     this.isZero = false
     // 删除目标路径缓存
     setTimeout(() => {
@@ -3019,14 +3007,13 @@ export struct LocalMusic {
 
     let newUris: string[] = [];
     this.progress = 0
-    DialogHelper.showLoadingProgress({
+    this.loadingProgressDialogId = DialogHelper.showLoadingProgress({
       progress: this.progress,
       backCancel: false,
       autoCancel: false,
       loadColor: this.themeColor,
       fontColor: this.themeColor
     });
-    this.loadingProgressDialogId = '';
     // 计算所有文件的总大小
     let totalSize = 0;
     for (let uri of uris) {
@@ -3058,7 +3045,7 @@ export struct LocalMusic {
 
           // 计算总进度
           this.progress = Math.floor((totalRead / totalSize) * 100);
-          DialogHelper.updateLoading(`正在导入 ${this.progress}%`, this.progress);
+          DialogHelper.updateLoading( this.loadingProgressDialogId,`正在导入 ${this.progress}%`, this.progress);
 
           len = await fileIo.read(sourceFile.fd, buffer);
         }
@@ -3088,16 +3075,10 @@ export struct LocalMusic {
 
 
     }
-
-    this.closeLoadingProgressDialog()
+    DialogHelper.closeDialog(this.loadingProgressDialogId);
     this.isZero = false
-    this.loadingProgressDialogId = ''
 
-    // setTimeout(() => {
-    //   // 删除目标路径缓存
-    //   this.cache.delete(this.currentPath);
-    //   this.getSortedFiles(this.currentPath,true,destPath,isOpen)
-    // }, 500);
+
 
 
     Logger.info(TAG, 'scan select video result:' + newUris)
@@ -7419,8 +7400,7 @@ export struct LocalMusic {
     }
     //内嵌音乐标签不能开启监听
     // this.deletionWatcher?.stop();
-    DialogHelper.showLoadingDialog()
-    this.loadingDialogId = 'loading_dialog'
+    this.loadingDialogId  = DialogHelper.showLoadingDialog()
     await PermissionUtil.activatePermission(item.filePath)
     let tempOutPath = ''
     // 如果不是 packName 包下的文件,则直接路径用this.currentPath
@@ -7531,13 +7511,12 @@ export struct LocalMusic {
           console.error(" onecold  编辑信息数据库失败 ");
         }
         // 关闭进度条
-        this.closeLoadingDialog();
-
+        DialogHelper.closeDialog(this.loadingDialogId)
 
 
       }).catch((error: Error) => {
         // 关闭进度条
-        this.closeLoadingDialog();
+        DialogHelper.closeDialog(this.loadingDialogId)
         console.error('onecold Subtitle sync failed:', error);
       });
 
@@ -7546,7 +7525,7 @@ export struct LocalMusic {
 
     } else {
       // 关闭进度条
-      this.closeLoadingDialog();
+      DialogHelper.closeDialog(this.loadingDialogId)
       ToastUtil.showToast('内嵌音乐标签失败')
       console.log('onecold 内嵌音乐标签失败');
     }
@@ -7581,7 +7560,7 @@ export struct LocalMusic {
       }
 
     }
-    this.closeLoadingDialog();
+    DialogHelper.closeDialog(this.loadingDialogId)
   }
 
   @Builder

+ 21 - 9
entry/src/main/ets/view/NavidromePage.ets

@@ -1232,6 +1232,13 @@ export struct NavidromePage {
   private convertSongToVideoItem(song: NavidromeRestSong, account: WebDavAccount, coverUrl?: string): VideoItem {
     const title = song.title ?? Constants.UNKNOWN_TITLE;
     const libraryInfo = this.resolveLibraryInfo(account);
+
+    // 调试日志:记录从playlist或其他API获取的歌曲的id字段
+    void ServerLogUtil.debug('SongConvert', `转换歌曲: ${title}`);
+    void ServerLogUtil.debug('SongConvert', `- song.id: ${song.id}`);
+    void ServerLogUtil.debug('SongConvert', `- song.artistId: ${song.artistId}`);
+    void ServerLogUtil.debug('SongConvert', `- song.albumId: ${song.albumId}`);
+
     const videoItem = new VideoItem(
       title,
       song.id,
@@ -1257,7 +1264,7 @@ export struct NavidromePage {
     videoItem.navArtistId = song.artistId;
     videoItem.navAlbumId = song.albumId;
     videoItem.pixelMapPath = coverUrl;
-    
+
     // 调试日志:检查歌曲的 albumId 和 artistId
     if (this.allVideos.length < 3) {
       Logger.info('heanup', `歌曲 ${title}: artistId=${song.artistId}, albumId=${song.albumId}, artist=${song.artist}, album=${song.album}`);
@@ -1271,6 +1278,11 @@ export struct NavidromePage {
     if (song.contentType) {
       videoItem.mimeType = song.contentType;
     }
+
+    // 记录最终生成的VideoItem路径
+    void ServerLogUtil.debug('SongConvert', `- VideoItem.filePath: ${videoItem.filePath}`);
+    void ServerLogUtil.debug('SongConvert', `- VideoItem.remote_rel_path: ${videoItem.remote_rel_path}`);
+
     return videoItem;
   }
 
@@ -1913,14 +1925,14 @@ export struct NavidromePage {
             .maxLines(1)
             .textOverflow({ overflow: TextOverflow.Ellipsis })
 
-          if (playlist.ownerName) {
-            Text(playlist.ownerName)
-              .fontSize(12)
-              .fontColor($r('app.color.index_tab_font_color'))
-              .opacity(0.5)
-              .maxLines(1)
-              .textOverflow({ overflow: TextOverflow.Ellipsis })
-          }
+          // if (playlist.ownerName) {
+          //   Text(playlist.ownerName)
+          //     .fontSize(12)
+          //     .fontColor($r('app.color.index_tab_font_color'))
+          //     .opacity(0.5)
+          //     .maxLines(1)
+          //     .textOverflow({ overflow: TextOverflow.Ellipsis })
+          // }
         }
         .alignItems(HorizontalAlign.Start)
         .padding({ right: 20 })