Przeglądaj źródła

加入提前缓存下一首的功能

onecold 7 miesięcy temu
rodzic
commit
a0375e9790

+ 14 - 12
entry/src/main/ets/common/util/RemotePlayerUtil.ets

@@ -96,6 +96,8 @@ export async function preloadNextSongIfNeeded(
   currentIndex: number,
   currentIndex: number,
   playType: number
   playType: number
 ): Promise<void> {
 ): Promise<void> {
+  Logger.info(TAG, `preloadNextSongIfNeeded 被调用 - songList长度: ${songList?.length || 0}, currentIndex: ${currentIndex}, playType: ${playType}`);
+
   const preloadEnabled = PreferencesUtil.getBooleanSync('preload_next_song', true);
   const preloadEnabled = PreferencesUtil.getBooleanSync('preload_next_song', true);
   if (!preloadEnabled) {
   if (!preloadEnabled) {
     Logger.info(TAG, '提前缓存下一首功能未启用');
     Logger.info(TAG, '提前缓存下一首功能未启用');
@@ -123,12 +125,12 @@ export async function preloadNextSongIfNeeded(
 
 
   // 如果下一首就是当前正在播放的(单曲循环),则不缓存
   // 如果下一首就是当前正在播放的(单曲循环),则不缓存
   if (nextIndex === currentIndex && playType === 1) {
   if (nextIndex === currentIndex && playType === 1) {
-    Logger.info(TAG, '单曲循环模式,无需提前缓存');
+    console.info(TAG, '单曲循环模式,无需提前缓存');
     return;
     return;
   }
   }
 
 
   const nextSong = songList[nextIndex];
   const nextSong = songList[nextIndex];
-  Logger.info(TAG, `准备提前缓存下一首: ${nextSong.name}, type: ${nextSong.type}`);
+  console.info(TAG, `准备提前缓存下一首: ${nextSong.name}, type: ${nextSong.type}`);
 
 
   try {
   try {
     // Navidrome
     // Navidrome
@@ -141,12 +143,12 @@ export async function preloadNextSongIfNeeded(
 
 
         void (async () => {
         void (async () => {
           try {
           try {
-            Logger.info(TAG, `后台提前缓存Navidrome下一首: ${navSongId}`);
+            console.info(TAG, `后台提前缓存Navidrome下一首: ${navSongId}`);
             await ensureNavidromeFileCached(account, navSongId, streamUrl, nextSong.videoSize);
             await ensureNavidromeFileCached(account, navSongId, streamUrl, nextSong.videoSize);
-            Logger.info(TAG, `Navidrome下一首提前缓存完成`);
+            console.info(TAG, `Navidrome下一首提前缓存完成`);
           } catch (error) {
           } catch (error) {
             const err = error as Error;
             const err = error as Error;
-            Logger.warn(TAG, `Navidrome下一首提前缓存失败: ${err.message}`);
+            console.warn(TAG, `Navidrome下一首提前缓存失败: ${err.message}`);
           }
           }
         })();
         })();
       }
       }
@@ -162,12 +164,12 @@ export async function preloadNextSongIfNeeded(
 
 
         void (async () => {
         void (async () => {
           try {
           try {
-            Logger.info(TAG, `后台提前缓存Jellyfin下一首: ${itemId}`);
+            console.info(TAG, `后台提前缓存Jellyfin下一首: ${itemId}`);
             await ensureJellyfinFileCached(account, itemId, streamUrl, nextSong.videoSize);
             await ensureJellyfinFileCached(account, itemId, streamUrl, nextSong.videoSize);
-            Logger.info(TAG, `Jellyfin下一首提前缓存完成`);
+            console.info(TAG, `Jellyfin下一首提前缓存完成`);
           } catch (error) {
           } catch (error) {
             const err = error as Error;
             const err = error as Error;
-            Logger.warn(TAG, `Jellyfin下一首提前缓存失败: ${err.message}`);
+            console.warn(TAG, `Jellyfin下一首提前缓存失败: ${err.message}`);
           }
           }
         })();
         })();
       }
       }
@@ -183,19 +185,19 @@ export async function preloadNextSongIfNeeded(
 
 
         void (async () => {
         void (async () => {
           try {
           try {
-            Logger.info(TAG, `后台提前缓存Emby下一首: ${itemId}`);
+            console.info(TAG, `后台提前缓存Emby下一首: ${itemId}`);
             await ensureEmbyFileCached(account, itemId, streamUrl, nextSong.videoSize);
             await ensureEmbyFileCached(account, itemId, streamUrl, nextSong.videoSize);
-            Logger.info(TAG, `Emby下一首提前缓存完成`);
+            console.info(TAG, `Emby下一首提前缓存完成`);
           } catch (error) {
           } catch (error) {
             const err = error as Error;
             const err = error as Error;
-            Logger.warn(TAG, `Emby下一首提前缓存失败: ${err.message}`);
+            console.warn(TAG, `Emby下一首提前缓存失败: ${err.message}`);
           }
           }
         })();
         })();
       }
       }
     }
     }
   } catch (error) {
   } catch (error) {
     const err = error as Error;
     const err = error as Error;
-    Logger.warn(TAG, `提前缓存下一首失败: ${err.message}`);
+    console.warn(TAG, `提前缓存下一首失败: ${err.message}`);
   }
   }
 }
 }
 
 

+ 4 - 5
entry/src/main/ets/view/LocalMusic.ets

@@ -12735,7 +12735,8 @@ export struct LocalMusic {
       this.startPlay(startOffset)
       this.startPlay(startOffset)
     }
     }
 
 
-
+    // 提前缓存下一首
+    void this.preloadNextSongInternal();
   }
   }
 
 
   startPlay(startOffset?:number) {
   startPlay(startOffset?:number) {
@@ -14173,15 +14174,13 @@ export struct LocalMusic {
           this.opacityValueImage = 1;
           this.opacityValueImage = 1;
           this.scaleValueImage = 1 // 图标恢复到原始大小
           this.scaleValueImage = 1 // 图标恢复到原始大小
           this.startPlayOrResumePlay()
           this.startPlayOrResumePlay()
-          // 提前缓存下一首
-          void this.preloadNextSongInternal();
+
         });
         });
       }, 500);
       }, 500);
     }else{
     }else{
       this.cover = this.songList[this.curIndex].pixelMapPath
       this.cover = this.songList[this.curIndex].pixelMapPath
       this.startPlayOrResumePlay()
       this.startPlayOrResumePlay()
-      // 提前缓存下一首
-      void this.preloadNextSongInternal();
+
     }
     }
 
 
   }
   }