Procházet zdrojové kódy

清理优化重复代理

chendeben před 9 měsíci
rodič
revize
5ddb365a5f
1 změnil soubory, kde provedl 18 přidání a 94 odebrání
  1. 18 94
      entry/src/main/ets/view/LocalMusic.ets

+ 18 - 94
entry/src/main/ets/view/LocalMusic.ets

@@ -13560,23 +13560,8 @@ export struct LocalMusic {
       this.currentSong = this.songList[this.curIndex];
       Logger.info('heanup playNext', `直接使用歌曲列表中的信息: ${this.currentSong.name}, type: ${this.currentSong.type}`);
 
-      // 设置videoUrl,WebDAV歌曲会通过VideoItem本身的数据构建完整URL
-      if(this.currentSong.type==CommonConstants.TYPE_WEBDAV){
-        if (this.currentSong.webdav_account_id) {
-          // 如果有webdav_account_id,优先使用remote_rel_path,否则使用filePath
-          const relativePath = this.currentSong.remote_rel_path || this.currentSong.filePath;
-          this.videoUrl = await WebDavUrlUtil.buildFullUrlByAccountId(
-            this.currentSong.webdav_account_id,
-            relativePath
-          );
-          Logger.info('heanup WebDAV playNext', `构建WebDAV URL: ${this.videoUrl}`);
-        } else {
-          Logger.warn('heanup WebDAV playNext', `缺少webdav_account_id,使用filePath`);
-          this.videoUrl = this.currentSong.filePath.replace(/ /g, '%20');
-        }
-      }else{
-        this.videoUrl = this.currentSong.filePath
-      }
+      // 设置videoUrl,WebDAV歌曲会通过webdav_account_id构建完整URL
+      this.videoUrl = await setVideoUrlForSong(this.currentSong);
 
       this.artist = this.songList[this.curIndex].artist
       this.name = this.songList[this.curIndex].name
@@ -13666,23 +13651,8 @@ export struct LocalMusic {
       this.stop();
       this.currentSong = this.songList[this.curIndex];
 
-      // 设置videoUrl,WebDAV歌曲需要构建完整的URL
-      if(this.currentSong.type==CommonConstants.TYPE_WEBDAV){
-        if (this.currentSong.webdav_account_id) {
-          // 如果有webdav_account_id,优先使用remote_rel_path,否则使用filePath
-          const relativePath = this.currentSong.remote_rel_path || this.currentSong.filePath;
-          this.videoUrl = await WebDavUrlUtil.buildFullUrlByAccountId(
-            this.currentSong.webdav_account_id,
-            relativePath
-          );
-          Logger.info('heanup randomPlay', `构建WebDAV URL: ${this.videoUrl}`);
-        } else {
-          Logger.warn('heanup randomPlay', `缺少webdav_account_id,使用filePath`);
-          this.videoUrl = this.currentSong.filePath.replace(/ /g, '%20');
-        }
-      }else{
-        this.videoUrl = this.currentSong.filePath
-      }
+      // 设置videoUrl,WebDAV歌曲会通过webdav_account_id构建完整URL
+      this.videoUrl = await setVideoUrlForSong(this.currentSong);
       this.name = this.songList[this.curIndex].name;
       this.artist = this.songList[this.curIndex].artist
       // this.cover = this.songList[this.curIndex].pixelMapPath
@@ -13690,7 +13660,7 @@ export struct LocalMusic {
     }
   }
 
-  private playIndex(index: number) {
+  private async playIndex(index: number) {
     if (!this.debounce()) {
       return;
     }
@@ -13698,15 +13668,14 @@ export struct LocalMusic {
 
       this.CONTROL_PlayStatus = PlayStatus.INIT;
       this.stop();
-      this.currentSong = this.songList[this.curIndex]
-      if(this.currentSong.type===CommonConstants.TYPE_WEBDAV){
-        this.videoUrl = this.songList[index].filePath.replace(/ /g, '%20');
-      }else{
-        this.videoUrl = this.songList[index].filePath
-      }
-      this.name = this.songList[index].name
-      this.artist = this.songList[this.curIndex].artist
       this.curIndex = index;
+      this.currentSong = this.songList[index];
+
+      // 设置videoUrl,WebDAV歌曲会通过webdav_account_id构建完整URL
+      this.videoUrl = await setVideoUrlForSong(this.currentSong);
+
+      this.name = this.currentSong.name
+      this.artist = this.currentSong.artist
       this.changeImageAnimation()
     }
 
@@ -13735,23 +13704,8 @@ export struct LocalMusic {
     this.currentSong = this.songList[this.curIndex];
     Logger.info('heanup playPrevious', `直接使用歌曲列表中的信息: ${this.currentSong.name}, type: ${this.currentSong.type}`);
 
-    // 设置videoUrl,WebDAV歌曲会通过VideoItem本身的数据构建完整URL
-    if(this.currentSong.type==CommonConstants.TYPE_WEBDAV){
-      if (this.currentSong.webdav_account_id) {
-        // 如果有webdav_account_id,优先使用remote_rel_path,否则使用filePath
-        const relativePath = this.currentSong.remote_rel_path || this.currentSong.filePath;
-        this.videoUrl = await WebDavUrlUtil.buildFullUrlByAccountId(
-          this.currentSong.webdav_account_id,
-          relativePath
-        );
-        Logger.info('heanup WebDAV playPrevious', `构建WebDAV URL: ${this.videoUrl}`);
-      } else {
-        Logger.warn('heanup WebDAV playPrevious', `缺少webdav_account_id,使用filePath`);
-        this.videoUrl = this.songList[this.curIndex].filePath.replace(/ /g, '%20');
-      }
-    }else{
-      this.videoUrl = this.songList[this.curIndex].filePath
-    }
+    // 设置videoUrl,WebDAV歌曲会通过webdav_account_id构建完整URL
+    this.videoUrl = await setVideoUrlForSong(this.currentSong);
     this.name = this.songList[this.curIndex].name
     this.artist = this.songList[this.curIndex].artist
     this.changeImageAnimation()
@@ -13770,23 +13724,8 @@ export struct LocalMusic {
       this.currentSong = prevSong;
       Logger.info('heanup randomModePlayFromHistory', `直接使用历史歌曲信息: ${prevSong.name}, type: ${prevSong.type}`);
 
-      // 设置videoUrl
-      if(this.currentSong.type==CommonConstants.TYPE_WEBDAV){
-        if (this.currentSong.webdav_account_id) {
-          // 如果有webdav_account_id,优先使用remote_rel_path,否则使用filePath
-          const relativePath = this.currentSong.remote_rel_path || this.currentSong.filePath;
-          this.videoUrl = await WebDavUrlUtil.buildFullUrlByAccountId(
-            this.currentSong.webdav_account_id,
-            relativePath
-          );
-          Logger.info('heanup WebDAV randomModePlayFromHistory', `构建WebDAV URL: ${this.videoUrl}`);
-        } else {
-          Logger.warn('heanup WebDAV randomModePlayFromHistory', `缺少webdav_account_id,使用filePath`);
-          this.videoUrl = prevSong.filePath.replace(/ /g, '%20');
-        }
-      }else{
-        this.videoUrl = prevSong.filePath
-      }
+      // 设置videoUrl,WebDAV歌曲会通过webdav_account_id构建完整URL
+      this.videoUrl = await setVideoUrlForSong(this.currentSong);
       this.cover = prevSong.pixelMapPath
       this.artist = prevSong.artist
       this.name = prevSong.name;
@@ -13806,23 +13745,8 @@ export struct LocalMusic {
       this.currentSong = this.songList[this.curIndex];
       Logger.info('heanup randomModePlayFromHistory', `直接使用歌曲列表中的信息: ${this.currentSong.name}, type: ${this.currentSong.type}`);
 
-      // 设置videoUrl
-      if(this.currentSong.type==CommonConstants.TYPE_WEBDAV){
-        if (this.currentSong.webdav_account_id) {
-          // 如果有webdav_account_id,优先使用remote_rel_path,否则使用filePath
-          const relativePath = this.currentSong.remote_rel_path || this.currentSong.filePath;
-          this.videoUrl = await WebDavUrlUtil.buildFullUrlByAccountId(
-            this.currentSong.webdav_account_id,
-            relativePath
-          );
-          Logger.info('heanup WebDAV randomModePlayFromHistory', `构建WebDAV URL: ${this.videoUrl}`);
-        } else {
-          Logger.warn('heanup WebDAV randomModePlayFromHistory', `缺少webdav_account_id,使用filePath`);
-          this.videoUrl = this.songList[this.curIndex].filePath.replace(/ /g, '%20');
-        }
-      }else{
-        this.videoUrl =  this.songList[this.curIndex].filePath
-      }
+      // 设置videoUrl,WebDAV歌曲会通过webdav_account_id构建完整URL
+      this.videoUrl = await setVideoUrlForSong(this.currentSong);
       this.artist = this.songList[this.curIndex].artist
       this.name = this.songList[this.curIndex].name;
       this.changeImageAnimation()