فهرست منبع

优化歌词的透明度和模糊结合
实时保存排序模式
实时保存双指缩放的结果

onecold 1 سال پیش
والد
کامیت
3aa14c2efb
3فایلهای تغییر یافته به همراه72 افزوده شده و 51 حذف شده
  1. 32 7
      entry/src/main/ets/common/util/Utility.ets
  2. 38 43
      entry/src/main/ets/view/LocalMusic.ets
  3. 2 1
      lib/src/main/ets/view/LyricView2.ets

+ 32 - 7
entry/src/main/ets/common/util/Utility.ets

@@ -872,7 +872,6 @@ export class Utility {
             // Set additional properties from format metadata
             videoItem.artist  = artist;
             videoItem.album  = album;
-            videoItem.mimeType = format.format_name
             videoItem.sampleRate = sampleRate
             videoItem.pyStr = pinyin4js.getShortPinyin(name)
             videoItem.fileName  = FileUtil.getFileName(inputPath);
@@ -887,10 +886,7 @@ export class Utility {
             videoItem.lyricContent  = tags.LYRICS || tags.lyrics  ||  tags.USLT || tags.UNSYNCEDLYRICS || '';
             videoItem.genre  = tags.genre||tags.GENRE|| Utility.resourceToString(context, $r('app.string.unknown'));
             videoItem.track  = tags.track||tags.TRACK|| Utility.resourceToString(context, $r('app.string.unknown'));
-
-            if(sampleRate&&format.bit_rate){
-              videoItem.md5Str = determineAudioQuality( videoItem.mimeType,Number(format.bit_rate),Number(sampleRate))
-            }
+            videoItem.mimeType = format.format_name
             // 检查是否有封面图片流
             const hasCover = metadata.streams.some(stream  =>
             stream.disposition?.attached_pic  === 1
@@ -909,12 +905,16 @@ export class Utility {
               }else if(Utility.isVideoByExtension(inputPath)){
                 //提取封面
                 await getVideoFFmpegCover(inputPath, imagePath);
+                videoItem.mimeType = getFileFormatByPath(inputPath)
                 imagePath = fileUri.getUriFromPath(imagePath)
                 videoItem.pixelMapPath  = imagePath;
               }
             } catch (error) {
               console.warn(' 提取封面图片失败:', error.message);
             }
+            if(sampleRate&&format.bit_rate){
+              videoItem.md5Str = determineAudioQuality( videoItem.mimeType,Number(format.bit_rate),Number(sampleRate))
+            }
             console.info('Successfully  parsed metadata:', videoItem);
             resolve(videoItem);
           })
@@ -1600,8 +1600,15 @@ async function getFFmpegCover(inputPath: string, outputPath: string) {
  * @param inputPath 文件路径
  * @returns Promise<void>
  */
-async function getVideoFFmpegCover(inputPath: string, outputPath: string) {
-  let commands = ["ffmpeg", "-y","-i", inputPath, "-ss", "00:00:05", "-t", "1","-r",'1','-q:v','2','-f','image2', outputPath];
+async function getVideoFFmpegCover(inputPath: string, outputPath: string,duration?:string) {
+  let durationText = "00:00:05"
+  if(duration&&Number(duration) >300000){//如果时间超过5分钟,截10s的缩略图
+    durationText = "00:00:10"
+  }
+  if(duration&&Number(duration) <5000){//如果时间小5s,截0s的缩略图
+    durationText = "00:00:01"
+  }
+  let commands = ["ffmpeg", "-y","-i", inputPath, "-ss", "00:00:03", "-t", "1","-r",'1','-q:v','2','-f','image2', outputPath];
   FFmpeg.execute(commands, {
     logCallback: (logLevel: number, logMessage: string) => {
       console.info(`[FFmpegX LOG] [${logLevel}]${logMessage}`)
@@ -1809,3 +1816,21 @@ function determineAudioQuality(
   }
 }
 
+function getFileFormatByPath(filePath: string): string {
+  // 检查文件路径是否有效
+  if (!filePath || filePath.length  === 0) {
+    console.error(' 文件路径不能为空');
+    return '';
+  }
+
+  // 获取最后一个点号的位置
+  const lastDotIndex = filePath.lastIndexOf('.');
+
+  // 如果没有点号或者点号在最后一位,返回空字符串
+  if (lastDotIndex === -1 || lastDotIndex === filePath.length  - 1) {
+    return '';
+  }
+
+  // 返回点号后的部分(转换为小写)
+  return filePath.substring(lastDotIndex  + 1).toLowerCase();
+}

+ 38 - 43
entry/src/main/ets/view/LocalMusic.ets

@@ -1206,6 +1206,7 @@ export struct LocalMusic {
       transition: AnimationHelper.transitionInDown(555),
       onAction: (index) => {
         this.doSortType(index)
+        PreferencesUtil.put(SettingPage.SORT_TYPE, index)
         this.updateListData(this.videoLocalList, true)
       }
     })
@@ -3553,7 +3554,7 @@ export struct LocalMusic {
         this.isGridMusic = false
       }
     }
-
+    PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
     this.pinchValue = 1;
     this.scaleValue = 1;
   }
@@ -3906,6 +3907,7 @@ export struct LocalMusic {
 
       }
     }
+    PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
     this.pinchValue = 1;
     this.scaleValue = 1;
   }
@@ -4364,6 +4366,11 @@ export struct LocalMusic {
           this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
         }
 
+        //进入歌单的时候的滚动位置在顶部
+        if (this.isGridMusic) {
+          this.scroller.scrollToIndex(0)
+        }
+
         break;
       case CommonConstants.TYPE_IS_ALBUM:
         // 进入专辑前安全保存当前滚动偏移量,支持列表和网格
@@ -5134,20 +5141,6 @@ export struct LocalMusic {
         .margin({ top: 10, bottom: 10 })
         .justifyContent(FlexAlign.Start)
 
-        Row() {
-          Text('音轨数:')
-            .fontSize(14)
-            .fontColor(Color.White)
-            .margin({ left: 22 })
-          Text(StrUtil.isEmpty(currentItem.trackCount)?'1':currentItem.trackCount)
-            .fontSize(14)
-            .margin({ left: 10 })
-            .fontColor(Color.White)
-            .layoutWeight(1)
-        }
-        .width('100%')
-        .margin({ top: 10, bottom: 10 })
-        .justifyContent(FlexAlign.Start)
 
         Row() {
           Text('格式:')
@@ -5887,9 +5880,9 @@ export struct LocalMusic {
     // LogUtil.info('twocold this.currentWidthBreakpoint = '+this.currentWidthBreakpoint)
     LogUtil.info('hicar isPhoneLan width= ' + this.windowWidth);
     LogUtil.info('hicar isPhoneLan height= ' + this.windowHeight);
-    LogUtil.info(`twocold  hicarWindow size: ${this.windowWidth}x${this.windowHeight}, isHiCar: ${this.isHiCar()}`);
+    LogUtil.info(`twocold  hicarWindow size: ${this.windowWidth}x${this.windowHeight}, this.isHiCarStatus: ${this.isHiCarStatus}`);
     LogUtil.info(`twocold  hicar Window size: ${this.windowWidth}x${this.windowHeight}, isHiCarSmall: ${this.isHiCarSmall()}`);
-    if (this.isHiCar()) {
+    if (this.isHiCarStatus) {
       return false
     }
 
@@ -5962,29 +5955,31 @@ export struct LocalMusic {
 
   isHiCar() {
 
-    const hiCarAspectRatios: HiCarAspectRatio[] = [
-      { ratio: 800 / 480, name: "800x480" },
-      { ratio: 762 / 752, name: "762x752" },
-      { ratio: 968 / 1280, name: "968x1280" },
-      { ratio: 1200 / 1200, name: "1200x1200" },
-      { ratio: 1280 / 720, name: "1280x720" },
-      { ratio: 1920 / 720, name: "1920x720" },
-      { ratio: 1920 / 1080, name: "1920x1080" }
-    ];
-    const currentRatio: number = this.windowWidth / this.windowHeight;
-    const RATIO_TOLERANCE: number = 0.18; // 宽高比容差
-    LogUtil.info('twocold currentRatio = ' + currentRatio)
-
-    for (const hiCarRatio of hiCarAspectRatios) {
-      LogUtil.info('twocold hiCarRatio= ' + hiCarRatio.ratio)
-      LogUtil.info('twocold Math.abs(currentRatio - hiCarRatio.ratio)= ' + Math.abs(currentRatio - hiCarRatio.ratio))
-      if (Math.abs(currentRatio - hiCarRatio.ratio) <= RATIO_TOLERANCE) {
-        // LogUtil.info(`HiCar detected: ${hiCarRatio.name}, actual: ${this.windowWidth}x${this.windowHeight}`);
-        return true&&this.isHiCarStatus;
-      }
-    }
-
-    return false;
+    return this.isHiCarStatus;
+
+    // const hiCarAspectRatios: HiCarAspectRatio[] = [
+    //   { ratio: 800 / 480, name: "800x480" },
+    //   { ratio: 762 / 752, name: "762x752" },
+    //   { ratio: 968 / 1280, name: "968x1280" },
+    //   { ratio: 1200 / 1200, name: "1200x1200" },
+    //   { ratio: 1280 / 720, name: "1280x720" },
+    //   { ratio: 1920 / 720, name: "1920x720" },
+    //   { ratio: 1920 / 1080, name: "1920x1080" }
+    // ];
+    // const currentRatio: number = this.windowWidth / this.windowHeight;
+    // const RATIO_TOLERANCE: number = 0.18; // 宽高比容差
+    // LogUtil.info('twocold currentRatio = ' + currentRatio)
+    //
+    // for (const hiCarRatio of hiCarAspectRatios) {
+    //   LogUtil.info('twocold hiCarRatio= ' + hiCarRatio.ratio)
+    //   LogUtil.info('twocold Math.abs(currentRatio - hiCarRatio.ratio)= ' + Math.abs(currentRatio - hiCarRatio.ratio))
+    //   if (Math.abs(currentRatio - hiCarRatio.ratio) <= RATIO_TOLERANCE) {
+    //     // LogUtil.info(`HiCar detected: ${hiCarRatio.name}, actual: ${this.windowWidth}x${this.windowHeight}`);
+    //     return true&&this.isHiCarStatus;
+    //   }
+    // }
+    //
+    // return false;
   }
 
 
@@ -7981,8 +7976,8 @@ export struct LocalMusic {
           .fontColor(Color.White)
         Slider({
           value: isPip ? this.currentLyricLineSpacePip : this.currentLyricLineSpace,
-          min: 2,
-          max: 120,
+          min: 0,
+          max: 100,
           step: 1,
           style: SliderStyle.OutSet
         })
@@ -8051,7 +8046,7 @@ export struct LocalMusic {
           Slider({
             value: isPip ? this.blurDegreePip : this.blurDegree,
             min: 0,
-            max: 10,
+            max: 5,
             step: 0.1,
             style: SliderStyle.OutSet
           })

+ 2 - 1
lib/src/main/ets/view/LyricView2.ets

@@ -173,7 +173,8 @@ export struct LyricView2 {
 
     private calculateOpacityFactor(index: number, currentIndex: number): number {
         const distance = Math.abs(index - currentIndex);
-        return Math.max(0.26, 1 - distance * 0.11); // 透明度随着距离增加而减小
+        let maxOp =  Math.max(0.3,1-this.blurDegree*0.2)
+        return Math.max(maxOp, 1 - distance * 0.08); // 透明度随着距离增加而减小
     }