소스 검색

不是复制到DownLoad本app目录下 内嵌歌词和封面的权限处理和路径处理

onecold 9 달 전
부모
커밋
c28ca1756e
3개의 변경된 파일42개의 추가작업 그리고 20개의 파일을 삭제
  1. 3 0
      entry/src/main/ets/common/util/MusicTagUtils.ets
  2. 10 8
      entry/src/main/ets/common/util/Utility.ets
  3. 29 12
      entry/src/main/ets/view/LocalMusic.ets

+ 3 - 0
entry/src/main/ets/common/util/MusicTagUtils.ets

@@ -53,6 +53,9 @@ export async function repairAudioMetadata(
 
   if (outputPath && outputPath.length > 0) {
     finalOutputPath = outputPath;
+    if(FileUtil.accessSync(finalOutputPath)){
+
+    }
   } else if (overwrite) {
     // 使用临时文件方式处理覆盖,保持原文件扩展名
     const timestamp = new Date().getTime();

+ 10 - 8
entry/src/main/ets/common/util/Utility.ets

@@ -668,7 +668,9 @@ export class Utility {
   static async uriGetMusicAssetsFromFile(context:Context,uri:string,type:number,autoParseMusicName?:boolean): Promise<VideoItem> {
     await ReqPermissionUtil.persistPermission(uri);
     if(StrUtil.isNotEmpty(uri)&&uri.toLowerCase().endsWith('.cue')){
-      return  new VideoItem(FileUtil.getFileName(uri),uri,uri,type,0,'')
+      const cueItem = new VideoItem(FileUtil.getFileName(uri),uri,uri,type,0,'')
+      cueItem.fileName = FileUtil.getFileName(uri)
+      return  cueItem
     }
     return Utility.readMetaInfoFFmpeg(context,uri,type,autoParseMusicName)
 
@@ -1001,10 +1003,10 @@ export class Utility {
             const hasCover = metadata.streams.some(stream  =>
             stream.disposition?.attached_pic  === 1
             );
-            console.info('readMetaInfoFFmpeg asset hasCover: ', hasCover);
+            console.info('onecold readMetaInfoFFmpeg asset hasCover: ', hasCover);
             let md5Name = await MD5.digestSync(inputPath)
             let imagePath = `${context.filesDir}${FileUtil.separator}${md5Name}.jpg`;
-            console.info('readMetaInfoFFmpeg asset imagePath: ', imagePath);
+            console.info('onecold readMetaInfoFFmpeg asset imagePath: ', imagePath);
             // 如果有封面图片,则提取
             try {
               if (hasCover) {
@@ -1029,22 +1031,22 @@ export class Utility {
                 videoItem.pixelMapPath  = imagePath;
               }
             } catch (error) {
-              console.warn(' 提取封面图片失败:', error.message);
+              console.warn('onecold 提取封面图片失败:', error.message);
             }
             if(sampleRate&&format.bit_rate){
               videoItem.md5Str = determineAudioQuality( videoItem.mimeType,Number(format.bit_rate),Number(sampleRate))
             }
-            console.info('Successfully  parsed metadata:', videoItem);
+            console.info('onecold Successfully  parsed metadata:', videoItem);
             resolve(videoItem);
           })
 
 
         } catch (error) {
-          console.error('Failed  to parse metadata:', error);
-          reject(new Error('Failed to parse metadata: ' + error.message));
+          console.error('onecold Failed  to parse metadata:', error);
+          reject(new Error('onecold Failed to parse metadata: ' + error.message));
         }
       }).catch((error: Error) => {
-        console.error(`Execution  failed with error: ${error.message}`);
+        console.error(`onecold Execution  failed with error: ${error.message}`);
         reject(error);
       });
     });

+ 29 - 12
entry/src/main/ets/view/LocalMusic.ets

@@ -1240,7 +1240,7 @@ export struct LocalMusic {
     Logger.info('onecold cachedValue = ' + cachedValue)
     const cachedHash = this.findStringCache(curPath + '_hash');
     const cachedDirList = this.findCache(curPath + "_dirList");
-    if (cachedValue !== undefined) {
+    if (cachedValue !== undefined&&!this.isRefreshing) {
       // this.videoLocalList = cachedValue;
       Logger.info('onecold 有缓存 cachedValue = ' + cachedValue)
       if (this.currentPath != this.rootPath) { //第一个封面赋值给currentTitleCover
@@ -1338,7 +1338,7 @@ export struct LocalMusic {
       // this.setButtonStatus()
       this.openMusic(isOpen, destPath)
 
-
+      this.isRefreshing = false
 
     });
 
@@ -2716,6 +2716,7 @@ export struct LocalMusic {
               this.isEditAudio = !this.isEditAudio
               this.longItemFilePath = ''
               this.modeType = 0
+              this.isShowFileName = true
               this.getSortedFiles(FileUtil.getParentPath(outPutPath))
             },
             onPlayOrPause:()=>{
@@ -2789,6 +2790,7 @@ export struct LocalMusic {
               this.isConverter = !this.isConverter
               this.longItemFilePath = ''
               this.modeType = 0
+              this.isShowFileName = true
               this.getSortedFiles(FileUtil.getParentPath(outPutPath))
             },
             onSliderChange:(value:number)=>{
@@ -2850,6 +2852,7 @@ export struct LocalMusic {
               this.isExtractAcc = !this.isExtractAcc
               this.longItemFilePath = ''
               this.modeType = 0
+              this.isShowFileName = true
               this.getSortedFiles(FileUtil.getParentPath(outPutPath))
             },
             onSliderChange:(value:number)=>{
@@ -2917,6 +2920,7 @@ export struct LocalMusic {
               this.isAIVoiceSeparation = !this.isAIVoiceSeparation
               this.longItemFilePath = ''
               this.modeType = 0
+              this.isShowFileName = true
               this.getSortedFiles(FileUtil.getParentPath(outPutPath))
             },
             onSliderChange:(value:number)=>{
@@ -2979,6 +2983,7 @@ export struct LocalMusic {
               this.isExtractAudio = !this.isExtractAudio
               this.longItemFilePath = ''
               this.modeType = 0
+              this.isShowFileName = true
               this.getSortedFiles(FileUtil.getParentPath(outPutPath))
             },
             onSliderChange:(value:number)=>{
@@ -3041,6 +3046,7 @@ export struct LocalMusic {
               this.isMergeAudio = !this.isMergeAudio
               this.longItemFilePath = ''
               this.modeType = 0
+              this.isShowFileName = true
               this.getSortedFiles(FileUtil.getParentPath(outPutPath))
             },
             onResult:(result: boolean,outPath:string)=>{
@@ -3489,8 +3495,13 @@ export struct LocalMusic {
 
               }))
             .onClick(()=>{
-              this.doPlay(item,index)
-              this.isShowPlay = true
+              if (this.isMultiSelect) {
+                const isChecked = this.selectedFiles.some(x => x.filePath == item.filePath);
+                this.handleFileSelection(item, !isChecked);
+              } else {
+                this.doPlay(item,index)
+                this.isShowPlay = true
+              }
             })
         }
 
@@ -5479,9 +5490,6 @@ export struct LocalMusic {
         if(this.modeType==0){
           this.getSortedFiles(this.currentPath)
         }
-        setTimeout(() => {
-          this.isRefreshing = false;
-        }, 100)
       }).catch((e:object)=>{
         console.info("task1 catch e: " + e);
       })
@@ -6505,7 +6513,11 @@ export struct LocalMusic {
     }
     DialogHelper.showLoadingDialog()
     await PermissionUtil.activatePermission(item.filePath)
-    const tempOutPath = this.currentPath + '/' + item.fileName
+    let tempOutPath = ''
+    // 如果不是 packName 包下的文件,则直接路径用this.currentPath
+    if(!item.filePath.toLowerCase().includes(this.packName)){
+      tempOutPath  = this.currentPath + '/' + item.fileName
+    }
     console.info('onecold tempOutPath ='+tempOutPath)
     //用户更改了封面,那就内嵌下封面
     if(StrUtil.isNotEmpty(this.imagePathStr)){
@@ -6533,10 +6545,15 @@ export struct LocalMusic {
       comment:this.commentStr,
       disc:this.discStr,
     };
-
+    let newInput = item.filePath
+    //内嵌标签歌路径如果不是包含包名,输入newInput要赋值tempOutPath,然后tempOutPath为空
+    if(!item.filePath.toLowerCase().includes(this.packName)){
+      newInput = tempOutPath
+      tempOutPath  = ''
+    }
     //内嵌下标签的值,设置overwrite为true会直接修改原文件
     const result:boolean = await repairAudioMetadata(
-      item.filePath,
+      newInput,
       this.lyricConStr,
       metadata,
       true,
@@ -6545,8 +6562,8 @@ export struct LocalMusic {
 
     if (result) {
       if(!item.filePath.includes(this.packName)){
-        //内嵌成功的歌路径如果不是包含包名,则入库
-        let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, tempOutPath,
+        //内嵌成功的歌路径如果不是包含包名,则入库
+        let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newInput,
           CommonConstants.TYPE_LOCAL, this.autoParseMusicName);
         this.table.insert(newItem, (id: number) => {
           //加入数据库