Explorar o código

修复内存占用大1G的问题,外面ets不不能这样引用LocalMusi.STR_LOCK_VIDEO

onecold hai 1 ano
pai
achega
9a6bf3fbe4

+ 4 - 0
entry/src/main/ets/common/constants/CommonConstants.ets

@@ -16,6 +16,10 @@
 import { SettingPage } from '../../pages/SettingPage';
 import { VideoSpeed } from '../../viewmodel/VideoSpeed';
 
+export const STR_LOCK_VIDEO: string = '.私密音频';
+export const STR_FAC_VIDEO: string = '.我的收藏';
+export const STR_HISTORY_MUSIC: string = '.最近播放';
+export const VIP_FILEPATH: string = '.vv'
 /**
  * Common constants for all features.
  */

+ 2 - 3
entry/src/main/ets/common/util/UserUtil.ets

@@ -1,13 +1,12 @@
 import { cryptoFramework } from "@kit.CryptoArchitectureKit";
 import { LogUtil, PreferencesUtil, StrUtil, ToastUtil } from "@pura/harmony-utils";
-import { CommonConstants } from "../constants/CommonConstants";
+import { CommonConstants, STR_LOCK_VIDEO, VIP_FILEPATH } from "../constants/CommonConstants";
 import { http } from "@kit.NetworkKit";
 import { bundleManager } from "@kit.AbilityKit";
 import { BusinessError } from '@kit.BasicServicesKit';
 import { hilog } from "@kit.PerformanceAnalysisKit";
 import { FileUtil } from "@pura/harmony-utils";
 import { fileUri, picker } from "@kit.CoreFileKit";
-import { LocalMusic } from "../../view/LocalMusic";
 import { VipPage } from "../../pages/VipPage";
 
 // 用户相关接口定义
@@ -430,7 +429,7 @@ export default class UserUtil {
             const documentViewPicker = new picker.DocumentViewPicker()
             let documentSaveResult = await documentViewPicker.save({ pickerMode: picker.DocumentPickerMode.DOWNLOAD })
             let download_path = new fileUri.FileUri(documentSaveResult[0]).path + '/'
-            let filePath = download_path + LocalMusic.STR_LOCK_VIDEO+ '/' + VipPage.VIP_FILEPATH
+            let filePath = download_path + STR_LOCK_VIDEO+ '/' + VIP_FILEPATH
             if (FileUtil.accessSync(filePath)) {
               FileUtil.unlink(filePath);
             }

+ 6 - 25
entry/src/main/ets/common/util/Utility.ets

@@ -17,12 +17,11 @@ import { dataSharePredicates, uniformTypeDescriptor } from '@kit.ArkData';
 import { systemShare } from '@kit.ShareKit';
 import { fileUri, picker } from '@kit.CoreFileKit';
 import {  common, UIAbility, Want } from '@kit.AbilityKit';
-import { CommonConstants } from '../constants/CommonConstants';
+import { CommonConstants, STR_LOCK_VIDEO, VIP_FILEPATH } from '../constants/CommonConstants';
 import { window } from '@kit.ArkUI';
 import { bundleManager } from '@kit.AbilityKit'
 import { pinyin4js } from '@ohos/pinyin4js';
 import { VipData } from '../../viewmodel/VipData';
-import { LocalMusic } from '../../view/LocalMusic';
 import { VipPage } from '../../pages/VipPage';
 import { FFmpeg, FFProgressMessageParser } from '@sj/ffmpeg';
 
@@ -812,7 +811,7 @@ export class Utility {
           let videoItem:VideoItem = new VideoItem('',inputPath,inputPath,type,0,'')
           const metadata: FFprobeMetadata = JSON.parse(outputJson);
           const format = metadata.format;
-
+          console.log(`onecold outputJson:${outputJson}`);
           let file = fs.openSync(inputPath, fs.OpenMode.READ_ONLY | fs.OpenMode.CREATE)
           console.info('readMetaInfoFFmpeg asset file.path: ', file.path);
           videoItem = new VideoItem(file.name,inputPath,inputPath,type,0,'')
@@ -1214,19 +1213,7 @@ export class Utility {
   }
 
 
-  static getFileDirName(filePath: string,rootPath:string): string{
-    if(filePath===rootPath){
-      return '首页'
-    }
-    let result = FileUtil.getFileName(filePath)
-    if(StrUtil.isEmpty(result))
-      return ''
-
 
-    if(result.startsWith('.'))
-      result = result.replace(/\./g, '')
-    return result
-  }
 
 
 
@@ -1358,7 +1345,7 @@ export class Utility {
       const documentViewPicker = new picker.DocumentViewPicker()
       let documentSaveResult = await documentViewPicker.save({ pickerMode: picker.DocumentPickerMode.DOWNLOAD })
       let download_path = new fileUri.FileUri(documentSaveResult[0]).path + '/'
-      let filePath = download_path + LocalMusic.STR_LOCK_VIDEO+ '/' + VipPage.VIP_FILEPATH
+      let filePath = download_path + STR_LOCK_VIDEO+ '/' + VIP_FILEPATH
       let expireDate =  Utility.readDataFromFile(filePath)
 
       return expireDate;
@@ -1600,15 +1587,9 @@ async function getFFmpegCover(inputPath: string, outputPath: string) {
  * @param inputPath 文件路径
  * @returns Promise<void>
  */
-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];
+async function getVideoFFmpegCover(inputPath: string, outputPath: string) {
+
+  let commands = ["ffmpeg", "-y","-i", inputPath, "-ss", "00:00:00", "-t", "1","-r",'1','-q:v','2','-f','image2', outputPath];
   FFmpeg.execute(commands, {
     logCallback: (logLevel: number, logMessage: string) => {
       console.info(`[FFmpegX LOG] [${logLevel}]${logMessage}`)

+ 2 - 1
entry/src/main/ets/pages/NewIndex.ets

@@ -16,7 +16,6 @@ import { common } from '@kit.AbilityKit';
 import { PrintBiddingTokenUtils } from '../common/util/PrintBiddintTokenUtils';
 import { ArrayList } from '@kit.ArkTS';
 import { CSJUtil } from '../common/util/CSJUtil';
-import { LocalMusic } from '../view/LocalMusic';
 import { StreamContent } from '../view/StreamContent';
 import { AvSessionController } from '../controller/AvSessionController';
 import { BreakpointSystem, BreakpointTypeEnum } from '../common/util/BreakpointSystem';
@@ -38,6 +37,8 @@ import { smartMobilityCommon } from '@kit.CarKit';
 import { UpdateLogManager } from '../common/util/UpdateLogManager';
 import OnlineUpdateLogDialog from '../dialog/OnlineUpdateLog';
 import OnlineUpdateLog from '../dialog/OnlineUpdateLog';
+import { LocalMusic } from '../view/LocalMusic';
+
 // import { FFmpeg, FFProgressMessageParser } from '@sj/ffmpeg';
 
 const TAG = 'NewIndex'; // 日志标签

+ 2 - 3
entry/src/main/ets/pages/ScanFilePage.ets

@@ -5,12 +5,11 @@ import lottie from '@ohos/lottie'
 import { AnimationItem } from '@ohos/lottie'
 import { MessageEvents, taskpool, worker } from '@kit.ArkTS'
 import { fileUri, picker } from '@kit.CoreFileKit'
-import { LocalMusic } from '../view/LocalMusic'
 import { Utility } from '../common/util/Utility'
 import MediaTable from '../common/util/MediaTable'
 import { VideoItem } from '../viewmodel/VideoItem'
 import Logger from '../common/util/Logger'
-import { CommonConstants } from '../common/constants/CommonConstants'
+import { CommonConstants, STR_LOCK_VIDEO } from '../common/constants/CommonConstants'
 import { emitter } from '@kit.BasicServicesKit'
 import { BreakpointTypeEnum } from '../common/util/BreakpointSystem'
 import { resourceManager } from '@kit.LocalizationKit'
@@ -83,7 +82,7 @@ export struct ScanFilePage{
     let documentSaveResult = await documentViewPicker.save({ pickerMode: picker.DocumentPickerMode.DOWNLOAD })
     this.rootPath = new fileUri.FileUri(documentSaveResult[0]).path
 
-    this.lockPath =  this.rootPath +'/'+ LocalMusic.STR_LOCK_VIDEO
+    this.lockPath =  this.rootPath +'/'+ STR_LOCK_VIDEO
     LogUtil.info('onecold 文件扫描 aboutToAppear')
     this.initLottie(this.path,true)
     setTimeout(()=>{

+ 2 - 3
entry/src/main/ets/pages/SplashIndex.ets

@@ -3,7 +3,7 @@ import { common } from '@kit.AbilityKit'
 import data_preferences from '@ohos.data.preferences'
 import Logger from '../common/util/Logger'
 import { router, window } from '@kit.ArkUI'
-import { CommonConstants } from '../common/constants/CommonConstants'
+import { CommonConstants, STR_LOCK_VIDEO, VIP_FILEPATH } from '../common/constants/CommonConstants'
 import { CSJUtil } from '../common/util/CSJUtil'
 import { ConfigManager } from '../common/util/ConfigManager'
 // import { AdSlotBuilder, CSJAdCreator, CSJAdSdk, CSJSplashAd,
@@ -17,7 +17,6 @@ import { DemoConstants } from '../entryability/DemoConstants'
 import { AppUtil, Base64Util, FileUtil, LogUtil, StrUtil, ToastUtil } from '@pura/harmony-utils'
 import { Utility } from '../common/util/Utility'
 import { VideoItem } from '../viewmodel/VideoItem'
-import { LocalMusic } from '../view/LocalMusic'
 import { fileIo, fileUri, picker, ReadTextOptions } from '@kit.CoreFileKit'
 import { VipPage } from './VipPage'
 import { VipData } from '../viewmodel/VipData'
@@ -142,7 +141,7 @@ struct  SplashIndex{
     let documentSaveResult = await documentViewPicker.save({ pickerMode: picker.DocumentPickerMode.DOWNLOAD })
     let download_path = new fileUri.FileUri(documentSaveResult[0]).path
     this.rootPath = download_path
-    let vPath = download_path + '/'+ LocalMusic.STR_LOCK_VIDEO+ '/' + VipPage.VIP_FILEPATH
+    let vPath = download_path + '/'+ STR_LOCK_VIDEO+ '/' + VIP_FILEPATH
     this.expireDate =  this.readDataFromFile(vPath)
     Utility.setNoble(this.expireDate)
     this.doMain()

+ 3 - 4
entry/src/main/ets/pages/VipPage.ets

@@ -1,7 +1,7 @@
 import { promptAction, router, window } from '@kit.ArkUI';
 import TitleBar from '../view/TitleBar';
 import { webview } from '@kit.ArkWeb';
-import { CommonConstants } from '../common/constants/CommonConstants';
+import { CommonConstants, STR_LOCK_VIDEO, VIP_FILEPATH } from '../common/constants/CommonConstants';
 import { AES,
   AppUtil,
   Base64Util,
@@ -19,7 +19,6 @@ import { Utility } from '../common/util/Utility';
 import fileIo, { ReadTextOptions } from '@ohos.file.fs';
 import { fileUri, picker } from '@kit.CoreFileKit';
 import { VipData } from '../viewmodel/VipData';
-import { LocalMusic } from '../view/LocalMusic';
 import { DialogHelper } from '@pura/harmony-dialog';
 import { common, ConfigurationConstant } from '@kit.AbilityKit';
 import * as wxOpenSdk from '@tencent/wechat_open_sdk';
@@ -67,7 +66,7 @@ export  struct  VipPage{
 
 
 
-  static readonly VIP_FILEPATH: string = '.vv'
+  // static readonly VIP_FILEPATH: string = '.vv'
 
   @State appName:string = ''
   @State expireDate:string = ''
@@ -104,7 +103,7 @@ export  struct  VipPage{
     const documentViewPicker = new picker.DocumentViewPicker()
     let documentSaveResult = await documentViewPicker.save({ pickerMode: picker.DocumentPickerMode.DOWNLOAD })
     let download_path = new fileUri.FileUri(documentSaveResult[0]).path + '/'
-    this.filePath = download_path + LocalMusic.STR_LOCK_VIDEO+ '/' + VipPage.VIP_FILEPATH
+    this.filePath = download_path + STR_LOCK_VIDEO+ '/' + VIP_FILEPATH
 
     this.expireDate =  this.readDataFromFile(this.filePath)
     this.bundleName = await  AppUtil.getBundleName()

+ 39 - 18
entry/src/main/ets/view/LocalMusic.ets

@@ -37,7 +37,7 @@ import { ColorConversion } from '../common/util/ColorConversion';
 import { LyricController, LyricParser, LyricView2 } from '@seagazer/cclyric';
 import { AvSessionController } from '../controller/AvSessionController';
 import {
-// DeviceChangeReason,
+  // DeviceChangeReason,
   IjkMediaPlayer,
   InterruptEvent,
   InterruptHintType,
@@ -884,11 +884,11 @@ export struct LocalMusic {
     }
     this.isCanBack = false
     this.currentPath = curPath
-    this.titleBarModel.setTitleName(Utility.getFileDirName(this.currentPath, this.rootPath))
+    this.titleBarModel.setTitleName(getFileDirName(this.currentPath, this.rootPath))
     if (curPath === this.rootPath) {
       this.titleBarModel.setLeftIconMain($r('app.media.menu'))
     } else {
-      this.currentTitleName = Utility.getFileDirName(this.currentPath, this.rootPath)
+      this.currentTitleName = getFileDirName(this.currentPath, this.rootPath)
       if (this.rootPath === Utility.getParentDirectory(curPath)) {
         this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
       }
@@ -2589,7 +2589,7 @@ export struct LocalMusic {
             Row() {
               Column(){
                 Text(item.md5Str?.includes('Lossless')?
-                   Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
+                Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
                   .fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
                   .padding({ top: 3,right:6,left:6,bottom:3 })
                   .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
@@ -2867,7 +2867,7 @@ export struct LocalMusic {
                     .padding({ top: 8 })
                     .maxLines(1)
                     .visibility(StrUtil.isEmpty(this.videoLocalList[0].year)||
-                       this.videoLocalList[0].year.includes(this.UNKONWN)
+                    this.videoLocalList[0].year.includes(this.UNKONWN)
                       ?Visibility.None:Visibility.Visible)
                     .fontWeight(FontWeight.Bold)
                     .fontColor($r('app.color.text_color'))
@@ -3503,7 +3503,7 @@ export struct LocalMusic {
     .layoutWeight(1)
     .scrollBar(BarState.Off)
     .supportAnimation(true)
-    .cachedCount(3)
+    .cachedCount(this.twoFingerType==1?5:this.twoFingerType==2?4:3)
     // .columnsTemplate('1fr '.repeat(this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM ? 2 : 5))
     .columnsTemplate(
       this.twoFingerType == 3 ? 'repeat(auto-fit, 160)' :
@@ -3533,7 +3533,7 @@ export struct LocalMusic {
       // if (this.isPhoneLan()) {
       //   this.setBarHeightHide(offset)
       // } else
-        if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
+      if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
         (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
           this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
         if (this.isScrollHide) {
@@ -3562,7 +3562,7 @@ export struct LocalMusic {
                   records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
                 let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
                 if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
-                 ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
+                  ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
                   this.targetFile = fileUriUds.oriUri;
                   this.saveVideoDatas([this.targetFile])
                   hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
@@ -3628,8 +3628,8 @@ export struct LocalMusic {
             })
             .draggable(false)
             .opacity(this.opacityItem)// 绑定透明度
-              // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
-              //   .animation({ duration: 500, curve: Curve.Ease }))
+            // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
+            //   .animation({ duration: 500, curve: Curve.Ease }))
             .animation({
               duration: 666,
               curve: 'ease-in-out' // 可选动画曲线
@@ -3677,7 +3677,7 @@ export struct LocalMusic {
                 }
                 .margin({ top: 2 ,right:6})
                 .visibility((this.modeType == 3 && !this.isCanBack)||(this.modeType == 2 && !this.isCanBack)
-                     ||(this.modeType == 0&&item.type==CommonConstants.TYPE_IS_DIR)? Visibility.None : Visibility.Visible)
+                  ||(this.modeType == 0&&item.type==CommonConstants.TYPE_IS_DIR)? Visibility.None : Visibility.Visible)
                 Text(StrUtil.isEmpty(item.artist) ? item.duration: item.artist)
                   .fontSize(11)
                   .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 14)
@@ -4180,7 +4180,7 @@ export struct LocalMusic {
       // if (this.isPhoneLan()) {
       //   this.setBarHeightHide(offset)
       // } else
-        if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
+      if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
         (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
           this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
         if (this.isScrollHide) {
@@ -4197,7 +4197,7 @@ export struct LocalMusic {
       return { offsetRemain: offset };
     })
 
-     //拖拽pc或者pad的用鼠标拖拽音乐和视频到List或Grid上自动导入视频
+    //拖拽pc或者pad的用鼠标拖拽音乐和视频到List或Grid上自动导入视频
     .allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
     .onDrop((event?: DragEvent) => {
       try {
@@ -5857,13 +5857,13 @@ export struct LocalMusic {
           // 使用更低的阈值和滑动速度判断
           const minDistance = 100; // 最小滑动距离 100vp
           const minVelocity = 500; // 最小滑动速度
-          
+
           // 获取滑动速度(如果可用)
           const velocity = event?.velocityY || 0;
-          
+
           // 判断是否应该关闭:距离足够 或者 速度足够快
           const shouldClose = this.translateY > minDistance || velocity > minVelocity;
-          
+
           if (shouldClose) {
             // 添加关闭动画
             this.getUIContext().animateTo({
@@ -6370,7 +6370,7 @@ export struct LocalMusic {
     let neiqianLrc = ''
     let lyContent = this.currentSong?.lyricContent
     if(lyContent&&StrUtil.isNotEmpty(lyContent)){//取数据库里面的歌词lyContent
-       neiqianLrc = lyContent
+      neiqianLrc = lyContent
     }
     if (StrUtil.isNotEmpty(neiqianLrc) && !isOnLineAndToast) {
       console.log("onecold 找到内嵌歌词 neiqianLrc =" + neiqianLrc)
@@ -9541,10 +9541,16 @@ export struct LocalMusic {
     this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", "1");
 
     const fileSize = await this.getFileSize(this.videoUrl);
-    let bufferSize = 1 * 1024 * 1024; // 默认缓冲区大小为2MB
+    let bufferSize = 1 * 1024 ; // 默认缓冲区大小为1MB
     if (fileSize > 3 * 1024 * 1024 * 1024) { // 文件大于3GB
       bufferSize = 25 * 1024 * 1024; // 设置缓冲区大小为25MB
     }
+    // 使用软件解码(通常比硬件解码更节省内存)
+    // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,  "mediacodec", '0');
+    // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,  "mediacodec-auto-rotate", '0');
+    // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,  "mediacodec-handle-resolution-change", '0');
+    // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,  "probesize", '1024');
+    // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,  "analyzeduration", '500000');
 
     //预读数据的缓冲区大小.修复大文件播放前几秒挂掉的bug,太大了会导致倍数播放失效
     this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-buffer-size", bufferSize + '');
@@ -11139,3 +11145,18 @@ function cutPopupBuilder(dataBu: BubbleBean) {
 }
 
 
+function getFileDirName(filePath: string,rootPath:string): string{
+  if(filePath===rootPath){
+    return '首页'
+  }
+  let result = FileUtil.getFileName(filePath)
+  if(StrUtil.isEmpty(result))
+    return ''
+
+
+  if(result.startsWith('.'))
+    result = result.replace(/\./g, '')
+  return result
+}
+
+