Эх сурвалжийг харах

修复播放列表网络图片不显示问题

chendeben 1 жил өмнө
parent
commit
1ade7f130c

+ 46 - 0
entry/src/main/ets/view/LocalMusic.ets

@@ -1471,6 +1471,48 @@ export struct LocalMusic {
 
   }
 
+  /**
+   * 刷新播放列表中歌曲的封面信息(从当前文件列表同步最新封面)
+   */
+  async refreshPlaylistCovers(): Promise<void> {
+    if (ArrayUtil.isEmpty(this.songList)) {
+      return;
+    }
+
+    try {
+      // 获取当前目录的最新文件列表(包含最新的封面信息)
+      const currentFileList = this.getCurFileList();
+      
+      // 如果当前文件列表为空,直接返回
+      if (ArrayUtil.isEmpty(currentFileList)) {
+        return;
+      }
+
+      // 为播放列表中的每首歌曲更新封面信息
+      let hasUpdates = false;
+      this.songList.forEach((song, index) => {
+        // 在当前文件列表中查找对应的歌曲
+        const matchedSong = currentFileList.find(file => file.filePath === song.filePath);
+        if (matchedSong && StrUtil.isNotEmpty(matchedSong.pixelMapPath) && 
+            matchedSong.pixelMapPath !== song.pixelMapPath) {
+          // 更新播放列表中的封面信息
+          this.songList[index].pixelMapPath = matchedSong.pixelMapPath;
+          hasUpdates = true;
+          LogUtils.getInstance().LOGI(`LocalMusic: Updated cover for ${song.name}: ${matchedSong.pixelMapPath}`);
+        }
+      });
+
+      // 如果有更新,刷新UI数据源
+      if (hasUpdates) {
+        this.sonDataSource.pushArrayData(this.songList);
+        LogUtils.getInstance().LOGI(`LocalMusic: Refreshed covers for playlist with ${this.songList.length} songs`);
+      }
+
+    } catch (error) {
+      LogUtils.getInstance().LOGI(`LocalMusic: Error refreshing playlist covers: ${error.message}`);
+    }
+  }
+
   setButtonStatus() {
 
     if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
@@ -4999,6 +5041,10 @@ export struct LocalMusic {
     }
     .width('100%')
     .height('100%')
+    .onAppear(() => {
+      // 播放列表显示时刷新封面信息
+      this.refreshPlaylistCovers();
+    })
   }
 
   @State titleStr: string = ''