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

编辑标签歌词的获取增加从数据库读取的方式

onecold 11 сар өмнө
parent
commit
6698627f80

+ 46 - 0
entry/src/main/ets/common/util/MediaTable.ets

@@ -693,6 +693,52 @@ export default class MediaTable {
   }
 
 
+  /**
+   * Get lyric content by file path (Promise version)
+   * @param filePath The file path to query
+   * @returns Promise that resolves with the lyric content (string) or null if not found
+   */
+  public getLyricContentByFilePath(filePath: string): Promise<string | null> {
+    return new Promise((resolve, reject) => {
+      // Create query predicates
+      const predicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
+      predicates.equalTo(DB_COLUMNS.FILE_PATH,  filePath);
+
+      // Execute the query
+      this.accountTable.query(predicates,  (resultSet: relationalStore.ResultSet) => {
+        try {
+          if (resultSet.rowCount  === 0) {
+            Logger.info(RdbUtils.RDB_TAG,  `No record found for filePath: ${filePath}`);
+            resolve(null);
+            return;
+          }
+
+          // Get the first row
+          resultSet.goToFirstRow();
+
+          // Get the column index safely
+          const columnIndex = resultSet.getColumnIndex(DB_COLUMNS.LYRIC_CONTENT);
+          if (columnIndex < 0) {
+            Logger.error(RdbUtils.RDB_TAG,  `Column ${DB_COLUMNS.LYRIC_CONTENT} not found`);
+            resolve(null);
+            return;
+          }
+
+          // Get the lyric content
+          const lyricContent = resultSet.getString(columnIndex);
+          resolve(lyricContent || null);
+        } catch (err) {
+          Logger.error(RdbUtils.RDB_TAG,  `Error getting lyric content: ${err.message}`);
+          reject(err);
+        } finally {
+          // Ensure the result set is closed
+          resultSet.close();
+        }
+      });
+    });
+  }
+
+
 }
 
 function generateBucket(item: VideoItem): relationalStore.ValuesBucket {

+ 7 - 2
entry/src/main/ets/pages/SettingPage.ets

@@ -1850,15 +1850,20 @@ export struct SettingPage {
     Column() {
       Image(this.customizeBgPath)
         .height('42%')
-        .alt($r('app.color.white'))
+        .alt($r('app.media.add_image2'))
         .objectFit(ImageFit.Contain)
-        .borderRadius(20)
+        .borderRadius(15)
         .clip(true)
         .clickEffect({ level: ClickEffectLevel.HEAVY })
         .blur(this.blurValue)
+        .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.6})
         .brightness(this.bgBrightness + 0.8)
         .margin({ left: 30, right: 30, bottom: 20 })
+        .onClick(async () => {
 
+          this.goSelectImage()
+
+        })
       Row() {
 
         Row() {

+ 87 - 70
entry/src/main/ets/view/LocalMusic.ets

@@ -4905,16 +4905,18 @@ export struct LocalMusic {
 
             Image(StrUtil.isNotEmpty(this.imagePathStr)?this.imagePathStr.startsWith('http')?
                 this.imagePathStr:fileUri.getUriFromPath(this.imagePathStr):
-                StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.add') :
+                StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.add_image2') :
                 item.pixelMapPath)
               .fillColor(this.themeColor)
               .height(88)
               .width(88)
-              .borderRadius('100%')
+              .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.6})
+              .borderRadius(12)
               .clip(true)
               .opacity(this.opacityItem)// 绑定透明度
               .margin({ left: 25 })
           }
+          .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.6})
           .onClick(async () => {
 
             const imagePath:string | undefined = await this.goSelectImage(item);
@@ -4929,7 +4931,7 @@ export struct LocalMusic {
           Row() {
             Column() {
               Text(item.name)
-                .fontSize(18)
+                .fontSize(17)
                 .maxLines(1)
                 .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
                 .animation({
@@ -4938,25 +4940,90 @@ export struct LocalMusic {
                 })
 
                 .fontColor(this.themeColor)
-                .margin({ left: 18 })
+                .margin({ left: 8 })
               Row() {
                 Text(item.artist)
-                  .fontSize(15)
+                  .fontSize(14)
                   .maxLines(1)
                   .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
                   .padding({ top: 8 })
                   .fontColor(this.themeColor)
-                  .margin({ left: 18 })
+                  .margin({ left: 8 })
 
               }
 
             }
             .height('100%')
             .width(100)
+            .layoutWeight(1)
             .visibility(this.isDarkMode ? Visibility.None : Visibility.Visible)
             .justifyContent(FlexAlign.Center)
             .alignItems(HorizontalAlign.Start)
 
+            Column() {
+              Button('获取封面')
+                .fontColor(Color.White)
+                .fontSize(12)
+                .height(38)
+                .width(88)
+                .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
+                .backgroundColor(this.themeColor)
+                .stateEffect(true)
+                .margin({  left: 5 })
+                .onClick(async () => {
+                  if (PreferencesUtil.getStringSync('COVER_API',  '') === '') {
+                    this.showTipsDialog();
+                    return; // Return empty string when no API is configured
+                  }
+
+                  const imagePath:string | undefined = await this.doSearchCover(item);
+                  console.info('onecold imagePath = '+imagePath)
+                  if (StrUtil.isNotEmpty(imagePath)) {
+                    //用户更改过图片
+                    this.imagePathStr = imagePath
+                    ToastUtil.showToast('获取封面成功')
+                  }else{
+                    ToastUtil.showToast('获取封面失败,请重试')
+                  }
+
+
+                })
+
+              Button('获取歌词')
+                .fontColor(Color.White)
+                .fontSize(12)
+                .height(38)
+                .width(88)
+                .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
+                .backgroundColor(this.themeColor)
+                .stateEffect(true)
+                .margin({ top: 9, left: 5 })
+                .onClick(async () => {
+                  //判断有没有设置api
+                  let apiUrl = PreferencesUtil.getStringSync('LRC_API', '')
+                  if (StrUtil.isEmpty(apiUrl)) {
+                    this.isLyricSetting = false
+                    this.showTipsDialog()
+                    return
+                  }
+                  let artist = item.artist
+                  let title = item.name
+                  if(!artist)
+                    artist = ''
+                  if(!title)
+                    title = ''
+                  let res: string | undefined = await getApiLyric(apiUrl,title, artist, false);
+                  if (res && StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
+                    this.lyricConStr = res;
+                    ToastUtil.showToast('获取歌词成功')
+                  }else{
+                    ToastUtil.showToast('获取歌词失败,请重试')
+                  }
+
+                })
+            }
+            .justifyContent(FlexAlign.Start)
+
 
           }
           .height('100%')
@@ -4967,70 +5034,7 @@ export struct LocalMusic {
         .width('100%')
         .height(98)
 
-        Row() {
-          Button('获取封面')
-            .fontColor(Color.White)
-            .fontSize(12)
-            .height(38)
-            .width(88)
-            .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
-            .backgroundColor(this.themeColor)
-            .stateEffect(true)
-            .margin({ right: 15, left: 20 })
-            .onClick(async () => {
-              if (PreferencesUtil.getStringSync('COVER_API',  '') === '') {
-                this.showTipsDialog();
-                return; // Return empty string when no API is configured
-              }
-
-              const imagePath:string | undefined = await this.doSearchCover(item);
-              console.info('onecold imagePath = '+imagePath)
-              if (StrUtil.isNotEmpty(imagePath)) {
-                //用户更改过图片
-                this.imagePathStr = imagePath
-                ToastUtil.showToast('获取封面成功')
-              }else{
-                ToastUtil.showToast('获取封面失败,请重试')
-              }
-
-
-            })
-
-          Button('获取歌词')
-            .fontColor(Color.White)
-            .fontSize(12)
-            .height(38)
-            .width(88)
-            .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
-            .backgroundColor(this.themeColor)
-            .stateEffect(true)
-            .margin({ right: 20, left: 15 })
-            .onClick(async () => {
-              //判断有没有设置api
-              let apiUrl = PreferencesUtil.getStringSync('LRC_API', '')
-              if (StrUtil.isEmpty(apiUrl)) {
-                this.isLyricSetting = false
-                this.showTipsDialog()
-                return
-              }
-              let artist = item.artist
-              let title = item.name
-              if(!artist)
-                artist = ''
-              if(!title)
-                title = ''
-              let res: string | undefined = await getApiLyric(apiUrl,title, artist, false);
-              if (res && StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
-                this.lyricConStr = res;
-                ToastUtil.showToast('获取歌词成功')
-              }else{
-                ToastUtil.showToast('获取歌词失败,请重试')
-              }
 
-            })
-        }
-        .height(55)
-        .justifyContent(FlexAlign.Start)
 
         Row() {
           Text('标题:')
@@ -7120,10 +7124,23 @@ export struct LocalMusic {
   async getLyricContent(item: VideoItem): Promise<string> {
     let neiqianLrc = ''
     let lyContent = item?.lyricContent
-    if(lyContent&&StrUtil.isNotEmpty(lyContent)){//取数据库里面的歌词lyContent
+    if(lyContent&&StrUtil.isNotEmpty(lyContent)){
       neiqianLrc = lyContent
       return neiqianLrc
     }
+    try {
+      //取数据库里面的歌词lyContent
+      const lyricContent = await this.table.getLyricContentByFilePath(item.filePath);
+      if (lyricContent&&StrUtil.isNotEmpty(lyricContent)) {
+        console.log("onecold Lyrics:",  lyricContent);
+        neiqianLrc = lyricContent
+        return neiqianLrc
+      }
+    } catch (error) {
+      console.error("Error  fetching lyrics:", error);
+    }
+
+
     try {
       let filePath = item.filePath;
       let lyricPath = filePath.substring(0, filePath.lastIndexOf('.')) + '.lrc';

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
entry/src/main/resources/base/media/add_image2.svg


Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно