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

编辑标签 歌词选项 添加+号选择本地歌词lrc功能和修复专辑艺术家字段的解析

onecold 11 месяцев назад
Родитель
Сommit
8b30a21017
2 измененных файлов с 74 добавлено и 56 удалено
  1. 2 1
      entry/src/main/ets/common/util/Utility.ets
  2. 72 55
      entry/src/main/ets/view/LocalMusic.ets

+ 2 - 1
entry/src/main/ets/common/util/Utility.ets

@@ -50,6 +50,7 @@ export interface FFMpegTags {
   LYRICIST?:string//作词家
   COMMENT?:string//注释
   albumartist?:string//专辑艺术家
+  album_artist?:string//专辑艺术家
   TPE2?:string//专辑艺术家
   composer?:string//作曲家
   lyricist?:string//作词家
@@ -940,7 +941,7 @@ export class Utility {
             videoItem.genre  = tags.genre||tags.GENRE|| '';
             videoItem.track  = tags.track||tags.TRACK|| '';
 
-            videoItem.ALBUMARTIST  = tags.ALBUMARTIST||tags.albumartist||tags.TPE2|| '';
+            videoItem.ALBUMARTIST  = tags.ALBUMARTIST||tags.album_artist||tags.albumartist||tags.TPE2|| '';
             videoItem.COMPOSER  = tags.COMPOSER||tags.composer|| '';
             videoItem.LYRICIST  = tags.LYRICIST||tags.lyricist||tags.TEXT ||'';
             videoItem.COMMENT  = tags.COMMENT||tags.comment||tags.COMM|| '';

+ 72 - 55
entry/src/main/ets/view/LocalMusic.ets

@@ -2138,16 +2138,16 @@ export struct LocalMusic {
             //
             //     this.showCutDialogForMultipleFiles(true, 'music_cut_current')
             //   })
-            Button('复制', { type: ButtonType.Circle, stateEffect: true })
-              .width('35%')
-              .height(60)
-              .id('music_copy_current')// .visibility(this.isHasDir?Visibility.None:Visibility.None)
-              .margin({ top: 10, bottom: 10, right: 6 })
-              .backgroundColor(this.themeColor)
-              .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
-              .onClick(() => {
-                this.showCopyDialogForMultipleFiles(false, 'music_copy_current')
-              })
+            // Button('复制', { type: ButtonType.Circle, stateEffect: true })
+            //   .width('35%')
+            //   .height(60)
+            //   .id('music_copy_current')// .visibility(this.isHasDir?Visibility.None:Visibility.None)
+            //   .margin({ top: 10, bottom: 10, right: 6 })
+            //   .backgroundColor(this.themeColor)
+            //   .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
+            //   .onClick(() => {
+            //     this.showCopyDialogForMultipleFiles(false, 'music_copy_current')
+            //   })
 
             Button('删除', { type: ButtonType.Circle, stateEffect: true })
               .width('35%')
@@ -4811,7 +4811,7 @@ export struct LocalMusic {
       TYER:this.yearStr,
       genre:this.genreStr,
       track:this.trackStr,
-      albumartist:this.albumArtistStr,
+      album_artist:this.albumArtistStr,
       TPE2:this.albumArtistStr,//ID3v2 中通常没有专门的 "专辑艺术家" 字段,但有些软件会使用 TPE2 来表示专辑艺
       COMPOSER:this.composerStr,
       lyricist:this.lyricistStr,
@@ -4905,11 +4905,11 @@ 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.music_red') :
+                StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.add') :
                 item.pixelMapPath)
               .fillColor(this.themeColor)
-              .height(55)
-              .width(55)
+              .height(66)
+              .width(66)
               .borderRadius('100%')
               .clip(true)
               .opacity(this.opacityItem)// 绑定透明度
@@ -5094,6 +5094,58 @@ export struct LocalMusic {
         .margin({ top: 10, bottom: 10 })
         .justifyContent(FlexAlign.Start)
 
+        Row() {
+          Column(){
+            Text('歌词:')
+              .fontSize(14)
+              .fontColor($r('app.color.text_color'))
+              .margin({ left: 22 })
+
+            Button({ type: ButtonType.Capsule, stateEffect: true }) {
+              SymbolGlyph($r('sys.symbol.trash_fill'))
+                .fontSize(25)
+                .alignSelf(ItemAlign.Center)
+                .margin({ left: 22,top:25})
+            }
+            .backgroundColor(Color.Transparent)
+            .visibility(StrUtil.isEmpty(this.tempLyricContent)&&StrUtil.isEmpty(this.lyricConStr)?
+            Visibility.None:Visibility.Visible)
+            .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
+            .onClick(()=>{
+              this.lyricConStr = ''
+              this.lyricContent = ''
+              this.tempLyricContent = ''
+            })
+
+            Button({ type: ButtonType.Capsule, stateEffect: true }) {
+              SymbolGlyph($r('sys.symbol.plus'))
+                .fontSize(25)
+                .alignSelf(ItemAlign.Center)
+                .margin({ left: 22,top:25})
+            }
+            .backgroundColor(Color.Transparent)
+            .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
+            .onClick( ()=>{
+              this.callFilePickerSelectFileForLyric()
+            })
+          }
+
+          TextArea({ text: StrUtil.isNotEmpty(this.lyricConStr)?this.lyricConStr:
+          this.tempLyricContent })
+            .type(TextAreaType.NORMAL)
+            .height(StrUtil.isEmpty(this.lyricConStr)&&StrUtil.isEmpty(this.tempLyricContent)?100:'auto')
+            .fontSize(14)
+            .layoutWeight(1)
+            .fontColor($r('app.color.text_color'))
+            .margin({ right: 20, left: 10 })
+            .onChange((val: string) => {
+              this.lyricConStr = val
+            })
+        }
+        .width('100%')
+        .margin({ top: 10, bottom: 10 })
+        .justifyContent(FlexAlign.Start)
+
         Row() {
           Text('年份:')
             .fontSize(14)
@@ -5257,45 +5309,7 @@ export struct LocalMusic {
         .margin({ top: 10, bottom: 10 })
         .justifyContent(FlexAlign.Start)
 
-        Row() {
-          Column(){
-            Text('歌词:')
-              .fontSize(14)
-              .fontColor($r('app.color.text_color'))
-              .margin({ left: 22 })
-
-            Button({ type: ButtonType.Capsule, stateEffect: true }) {
-              SymbolGlyph($r('sys.symbol.trash_fill'))
-                .fontSize(25)
-                .alignSelf(ItemAlign.Center)
-                .margin({ left: 22,top:15})
-            }
-            .backgroundColor(Color.Transparent)
-            .visibility(StrUtil.isEmpty(this.tempLyricContent)&&StrUtil.isEmpty(this.lyricConStr)?
-            Visibility.None:Visibility.Visible)
-            .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
-            .onClick(()=>{
-              this.lyricConStr = ''
-              this.lyricContent = ''
-              this.tempLyricContent = ''
-            })
-          }
 
-          TextArea({ text: StrUtil.isNotEmpty(this.lyricConStr)?this.lyricConStr:
-          this.tempLyricContent })
-            .type(TextAreaType.NORMAL)
-            .height('auto')
-            .fontSize(14)
-            .layoutWeight(1)
-            .fontColor($r('app.color.text_color'))
-            .margin({ right: 20, left: 10 })
-            .onChange((val: string) => {
-              this.lyricConStr = val
-            })
-        }
-        .width('100%')
-        .margin({ top: 10, bottom: 10 })
-        .justifyContent(FlexAlign.Start)
 
 
         Row() {
@@ -6817,7 +6831,7 @@ export struct LocalMusic {
    * - 支持加密歌词文件(.lrcc),自动检测并解密。
    * - 歌词内容解析后通过lyricController驱动UI渲染。
    */
-  async initLyric(lyricPath: string, isOnLineAndToast?: boolean, isApi2?: boolean) {
+  async initLyric(lyricPath: string, isOnLineAndToast?: boolean, isApi2?: boolean, isLocal?: boolean) {
     if (StrUtil.isEmpty(lyricPath)) {
       return
     }
@@ -6866,7 +6880,7 @@ export struct LocalMusic {
     if(lyContent&&StrUtil.isNotEmpty(lyContent)){//取数据库里面的歌词lyContent
       neiqianLrc = lyContent
     }
-    if (StrUtil.isNotEmpty(neiqianLrc) && !isOnLineAndToast) {
+    if (StrUtil.isNotEmpty(neiqianLrc) && !isOnLineAndToast&&!isLocal&&!isLocal) {
       console.log("onecold 找到内嵌歌词 neiqianLrc =" + neiqianLrc)
       //赋值给this.lyricContent,播控中心才可以显示歌词
       this.lyricContent = neiqianLrc
@@ -7005,6 +7019,9 @@ export struct LocalMusic {
             }
             console.info(`onecold The content of file2: ${fileContent}`);
             this.lyricContent = fileContent
+            if(isLocal){//编辑标签选择本地歌词需要赋值给this.lyricConStr
+              this.lyricConStr = fileContent
+            }
             // 将文件内容按行分割成字符串数组
             let lines = fileContent.split('\n').map(line => line.trim());
             console.info(`onecold The content of file: ${fileContent}`);
@@ -10040,7 +10057,7 @@ export struct LocalMusic {
       fileIo.copyFileSync(file.fd, file2.fd)
       fileIo.closeSync(file);
       fileIo.closeSync(file2);
-      this.initLyric(filePath)
+      this.initLyric(filePath,false,false,true)
     }
 
   }