Просмотр исходного кода

修复内嵌标签报错的bug

onecold 9 месяцев назад
Родитель
Сommit
0da693accb
2 измененных файлов с 99 добавлено и 42 удалено
  1. 5 5
      entry/src/main/ets/common/util/MediaTable.ets
  2. 94 37
      entry/src/main/ets/view/LocalMusic.ets

+ 5 - 5
entry/src/main/ets/common/util/MediaTable.ets

@@ -226,16 +226,16 @@ export default  class MediaTable {
   public updateMediaInfo(filePath: string, title: string, artist: string, album: string,
     lyricContent:string,year:string,genre:string,track:string,
     ALBUMARTIST:string,COMPOSER:string,LYRICIST:string,COMMENT:string,disc:string,
-    callback: Function) {
+    callback: Function): boolean {
     if (!callback || typeof callback !== 'function') {
       Logger.info(RdbUtils.RDB_TAG, 'updateMediaInfo() has no valid callback!');
-      return;
+      return false;
     }
 
     if (!this.accountTable) {
       Logger.error(RdbUtils.RDB_TAG, 'RdbStore is not initialized.');
       callback(false);
-      return;
+      return false;
     }
 
     // Step 1: Create a predicate to find the record by filePath
@@ -303,10 +303,10 @@ export default  class MediaTable {
         callback(false);
       }
     });
+    
+    return true; // 表示方法已成功启动
   }
 
-
-
   //更新重命名数据操作
   public updateRename(newName: string, oldPath: string, newPath: string, callback: Function) {
     // Step 1: 查询原始记录

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

@@ -1016,7 +1016,7 @@ export struct LocalMusic {
         case 101: //第一次扫描文件夹入库
           ToastUtil.showToast('刷新同步数据库成功!')
           Logger.info('onecold 扫描数据库结束 this.mediaKuList length= ' + this.mediaKuList.length)
-          this.doUpdateData()
+          this.doAllUpdateData()
           break;
         case 102: //查询媒体库列表
           this.isRefreshing = false
@@ -1384,8 +1384,8 @@ export struct LocalMusic {
       }
       if(openItem){
         this.doPlay(openItem,0,false,true)
-        this.isShowPlay = true
-        // this.setShowPlayTrue()
+        // this.isShowPlay = true
+        this.setShowPlayTrue()
       }
 
     }
@@ -6394,6 +6394,19 @@ export struct LocalMusic {
   @State discStr: string  = ''
 
   doUpdateData() {
+    setTimeout(() => {
+
+      if (this.modeType === 0) {
+        this.deleteCache(this.currentPath)
+        this.getSortedFiles(this.currentPath)
+      }else if (this.modeType === 1){
+        workerInstance.postMessage({ code: 2, data: this.context,data2:this.packName });
+      }
+
+    }, 999)
+  }
+
+  doAllUpdateData() {
     setTimeout(() => {
 
       if (this.modeType === 0) {
@@ -6403,6 +6416,7 @@ export struct LocalMusic {
       workerInstance.postMessage({ code: 2, data: this.context,data2:this.packName });
       workerInstance.postMessage({ code: 3, data: this.context });
       workerInstance.postMessage({ code: 4, data: this.context });
+
     }, 999)
   }
 
@@ -6477,45 +6491,57 @@ export struct LocalMusic {
           }
         });
       }
-      this.table.updateMediaInfo(item.filePath, this.titleStr, this.artistStr, this.ablumStr,this.lyricConStr,
-        this.yearStr,this.genreStr,this.trackStr,this.albumArtistStr,this.composerStr, this.lyricistStr,this.commentStr,this.discStr,
-        (success: boolean, error?: string) => {
-          // this.isShowEdit = false
 
-          if (success) {
-            console.log(" onecold 编辑信息成功,数据库已同步");
-            ToastUtil.showToast('内嵌音乐标签成功')
-            this.isShowMoreView = false
-            this.name = this.titleStr
-            if (item.filePath == this.currentSong?.filePath) {
-              this.currentSong.name = this.titleStr
-              this.artist = this.artistStr
-              this.currentSong.artist = this.artistStr
-              this.currentSong.album = this.ablumStr
-              this.currentSong.year = this.yearStr
-              this.currentSong.genre = this.genreStr
-              this.currentSong.track = this.trackStr
-              this.currentSong.lyricContent = this.lyricConStr
-              this.initLyric(item.filePath)
-
-              this.currentSong.ALBUMARTIST = this.albumArtistStr
-              this.currentSong.COMPOSER = this.composerStr
-              this.currentSong.LYRICIST = this.lyricistStr
-              this.currentSong.COMMENT = this.commentStr
-            }
-
-            this.doUpdateData()
-          } else {
-            // ToastUtil.showToast('保存失败' + error?.toString())
-            console.error(" onecold  编辑信息数据库失败原因: " + error);
+      const task = new taskpool.Task(
+        updateInfoDb,
+        this.context,
+        this.titleStr,
+        this.artistStr,
+        this.ablumStr,
+        this.lyricConStr,
+        this.yearStr,this.genreStr,
+        this.trackStr,this.albumArtistStr,
+        this.composerStr, this.lyricistStr,
+        this.commentStr,this.discStr,
+      );
+      taskpool.execute(task, taskpool.Priority.HIGH).then((result) => {
+        if (result) {
+          console.log(" onecold 编辑信息成功,数据库已同步");
+          ToastUtil.showToast('内嵌音乐标签成功')
+          this.isShowMoreView = false
+          this.name = this.titleStr
+          if (item.filePath == this.currentSong?.filePath) {
+            this.currentSong.name = this.titleStr
+            this.artist = this.artistStr
+            this.currentSong.artist = this.artistStr
+            this.currentSong.album = this.ablumStr
+            this.currentSong.year = this.yearStr
+            this.currentSong.genre = this.genreStr
+            this.currentSong.track = this.trackStr
+            this.currentSong.lyricContent = this.lyricConStr
+            this.initLyric(item.filePath)
+
+            this.currentSong.ALBUMARTIST = this.albumArtistStr
+            this.currentSong.COMPOSER = this.composerStr
+            this.currentSong.LYRICIST = this.lyricistStr
+            this.currentSong.COMMENT = this.commentStr
           }
 
-          // 关闭进度条
-          DialogHelper.closeLoading();
-        });
-      console.log(' onecold 元数据标签更新成功,');
+          this.doUpdateData()
+        } else {
+          // ToastUtil.showToast('保存失败' + error?.toString())
+          console.error(" onecold  编辑信息数据库失败 ");
+        }
+
+      }).catch((error: Error) => {
+        console.error('onecold Subtitle sync failed:', error);
+      });
 
 
+      console.log(' onecold 元数据标签更新成功,');
+
+      // 关闭进度条
+      DialogHelper.closeLoading();
     } else {
       // 关闭进度条
       DialogHelper.closeLoading();
@@ -14273,3 +14299,34 @@ async function scanCurrentDirectoryTask(context: Context, dirPath: string, lockP
     console.error(' 扫描当前目录失败:', error);
   }
 }
+
+//内嵌标签后更新库
+@Concurrent
+async function updateInfoDb(
+  context: Context,
+  filePath: string,
+  titleStr: string,
+  artistStr: string,
+  albumStr: string,
+  lyricConStr: string,
+  yearStr: string,
+  genreStr: string,
+  trackStr: string,
+  albumArtistStr: string,
+  composerStr: string,
+  lyricistStr: string,
+  commentStr: string,
+  discStr: string,
+): Promise<boolean> {
+  const table: MediaTable = new MediaTable(context);
+
+  return table.updateMediaInfo(filePath, titleStr, artistStr, albumStr, lyricConStr,
+    yearStr, genreStr, trackStr, albumArtistStr, composerStr, lyricistStr, commentStr, discStr,
+    (success: boolean, error?: string) => {
+      if (success) {
+        console.log("onecold 编辑信息成功,数据库已同步");
+      } else {
+        console.error("onecold 编辑信息数据库失败原因: " + error);
+      }
+    });
+}