onecold 1 жил өмнө
parent
commit
e5f1f24476

+ 42 - 1
entry/src/main/ets/common/util/MediaTable.ets

@@ -164,6 +164,15 @@ export default class MediaTable {
       obj.album  = resultSet.getString(resultSet.getColumnIndex('album'));
       obj.isFav  = resultSet.getDouble(resultSet.getColumnIndex('isFav'));
       obj.pixelMapPath = resultSet.getString(resultSet.getColumnIndex('pixelMapPath'));
+
+      obj.duration  = resultSet.getString(resultSet.getColumnIndex('duration'));
+      obj.mimeType  = resultSet.getString(resultSet.getColumnIndex('mimeType'));
+      obj.trackCount  = resultSet.getString(resultSet.getColumnIndex('trackCount'));
+      obj.sampleRate  = resultSet.getString(resultSet.getColumnIndex('sampleRate'));
+      obj.lastPlayedStr  = resultSet.getString(resultSet.getColumnIndex('lastPlayedStr'));
+      obj.playCount  = resultSet.getDouble(resultSet.getColumnIndex('playCount'));
+      obj.lyricContent  = resultSet.getString(resultSet.getColumnIndex('lyricContent'));
+
       const valueBucket: relationalStore.ValuesBucket = obj
       // Step 4: 执行更新
       const updatePredicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
@@ -388,7 +397,13 @@ export default class MediaTable {
     );
     item.isFav = rs.getDouble(rs.getColumnIndex('isFav'));
 
-
+    // item.duration = safeGet('duration');
+    item.mimeType = safeGet('mimeType');
+    item.trackCount =  safeGet('trackCount');
+    item.sampleRate = safeGet('sampleRate');
+    item.lastPlayedStr =safeGet('lastPlayedStr');
+    // item.playCount = rs.getDouble(rs.getColumnIndex('playCount'));
+    item.lyricContent =  safeGet('lyricContent')
 
     return item
   }
@@ -426,5 +441,31 @@ function generateBucket(item: VideoItem): relationalStore.ValuesBucket {
   if(item.pixelMapPath){
     obj.pixelMapPath = item.pixelMapPath;
   }
+
+
+  if(item.duration){
+    obj.duration = item.duration;
+  }
+  if(item.mimeType){
+    obj.mimeType = item.mimeType;
+  }
+  if(item.trackCount){
+    obj.trackCount = item.trackCount;
+  }
+
+  if(item.sampleRate){
+    obj.sampleRate = item.sampleRate;
+  }
+
+  if(item.lastPlayedStr){
+    obj.lastPlayedStr = item.lastPlayedStr;
+  }
+  if(item.playCount){
+    obj.playCount = item.playCount;
+  }
+  if(item.lyricContent){
+    obj.lyricContent = item.lyricContent;
+  }
+
   return obj;
 }

+ 28 - 1
entry/src/main/ets/common/util/RdbUtils.ets

@@ -1,6 +1,6 @@
 
 import relationalStore from '@ohos.data.relationalStore';
-import { StrUtil } from '@pura/harmony-utils';
+import { LogUtil, StrUtil } from '@pura/harmony-utils';
 import Logger from './Logger';
 import NetAxiosUtil from './NetAxiosUtil';
 
@@ -85,6 +85,33 @@ export default class RdbUtils {
       }
       this.rdbStore = rdb;
       this.rdbStore.executeSql(this.sqlCreateTable);
+      if (this.rdbStore.version  == 0) {
+          // 升级到版本1,添加列
+          // ✅ SQLite要求每列单独执行ALTER TABLE
+          const alterColumns = [
+            "ALTER TABLE mediaTable ADD COLUMN duration TEXT",
+            "ALTER TABLE mediaTable ADD COLUMN sampleRate TEXT",
+            "ALTER TABLE mediaTable ADD COLUMN playCount INTEGER DEFAULT 0",
+            "ALTER TABLE mediaTable ADD COLUMN lastPlayedStr TEXT",
+            "ALTER TABLE mediaTable ADD COLUMN trackCount TEXT",
+            "ALTER TABLE mediaTable ADD COLUMN lyricContent TEXT",
+            "ALTER TABLE mediaTable ADD COLUMN mimeType TEXT"
+          ];
+        try {
+          // 逐列执行添加
+          alterColumns.forEach(sql  => {
+            if(this.rdbStore)
+              this.rdbStore.executeSql(sql);
+          });
+          this.rdbStore.version = 1
+          LogUtil.info('onecold Upgrade  database from version 0 to 1 success.');
+        } catch (e) {
+          Logger.error(RdbUtils.RDB_TAG,  `Upgrade database failed: ${e}`);
+          // 注意:升级失败,可能需要处理,这里我们记录错误,但继续执行回调
+        }
+      }
+
+
       // Logger.info(RdbUtils.RDB_TAG, 'getRdbStore() finished.');
       callback();
     });

+ 31 - 0
entry/src/main/ets/common/util/Utility.ets

@@ -123,6 +123,15 @@ export class Utility {
     result.setDate(result.getDate() + days);
     return result;
   }
+
+  static convertToKHz(sampleRateHz: string|undefined): string {
+    if(StrUtil.isEmpty(sampleRateHz)||sampleRateHz ===undefined)
+      return '0KHz'
+
+    const sampleRateKHz = Number(sampleRateHz) / 1000;
+    return `${sampleRateKHz} KHz`;
+  }
+
   //根据字节获取大小
   static  formatFileSize(bytes:number) {
     const units = ['Bytes', 'Kbps', 'Mbps'];
@@ -627,6 +636,11 @@ export class Utility {
         let pixelMap:image.PixelMap|undefined|null = undefined
         let imagePath = ''
 
+        let duration:string | undefined = ''
+        let mimeType:string | undefined = ''
+        let trackCount:string | undefined = ''//轨道数量
+        let sampleRate:string | undefined = ''//音频的采样率单位为Hz
+
         if (canIUse("SystemCapability.Multimedia.Media.AVMetadataExtractor")) {
           try {
             // 创建AVMetadataExtractor对象
@@ -653,6 +667,19 @@ export class Utility {
               album = metadata.album
             }
 
+            if(StrUtil.isNotEmpty(metadata.duration)){
+              duration = metadata.duration
+            }
+            if(StrUtil.isNotEmpty(metadata.mimeType)){
+              mimeType = metadata.mimeType
+            }
+            if(StrUtil.isNotEmpty(metadata.trackCount)){
+              trackCount = metadata.trackCount
+            }
+            if(StrUtil.isNotEmpty(metadata.sampleRate)){
+              sampleRate = metadata.sampleRate
+            }
+
             let name = await MD5.digestSync(uri)
 
             if(isLoadPixelMap){
@@ -695,6 +722,10 @@ export class Utility {
 
         item = new VideoItem(musicName,uri ,uri,type,videoSize,addTime,undefined,fileSize,
           imagePath,artist,album,file.name)
+        item.duration = duration+'';
+        item.mimeType = mimeType;
+        item.trackCount = trackCount;
+        item.sampleRate = sampleRate;
         item.isFav = 0;
 
       })

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

@@ -286,7 +286,7 @@ async aboutToAppear() {
     List({space: 0, scroller: this.scroller}){
       ForEach(this.isShowSponsorship?mainViewModel.getDrawerData2():mainViewModel.getDrawerData(),(item: ItemData)=>{
         ListItem(){
-          Button({ type: ButtonType.Normal, stateEffect: true }) {
+          Button({ type: ButtonType.Capsule, stateEffect: true }) {
             Row() {
               // 菜单图标
               Image(item.img)

+ 51 - 5
entry/src/main/ets/view/LocalMusic.ets

@@ -4118,6 +4118,51 @@ export struct LocalMusic {
         .margin({ top: 10, bottom: 10 })
         .justifyContent(FlexAlign.Start)
 
+        Row() {
+          Text('时长:')
+            .fontSize(14)
+            .fontColor(Color.White)
+            .margin({ left: 22 })
+          Text(this.totalTime)
+            .fontSize(14)
+            .margin({ left: 10 })
+            .fontColor(Color.White)
+            .layoutWeight(1)
+        }
+        .width('100%')
+        .margin({ top: 10, bottom: 10 })
+        .justifyContent(FlexAlign.Start)
+
+        Row() {
+          Text('采样率:')
+            .fontSize(14)
+            .fontColor(Color.White)
+            .margin({ left: 22 })
+          Text(Utility.convertToKHz(this.currentSong.sampleRate))
+            .fontSize(14)
+            .margin({ left: 10 })
+            .fontColor(Color.White)
+            .layoutWeight(1)
+        }
+        .width('100%')
+        .margin({ top: 10, bottom: 10 })
+        .justifyContent(FlexAlign.Start)
+
+        Row() {
+          Text('格式:')
+            .fontSize(14)
+            .fontColor(Color.White)
+            .margin({ left: 22 })
+          Text(this.currentSong.mimeType)
+            .fontSize(14)
+            .margin({ left: 10 })
+            .fontColor(Color.White)
+            .layoutWeight(1)
+        }
+        .width('100%')
+        .margin({ top: 10, bottom: 10 })
+        .justifyContent(FlexAlign.Start)
+
         Row() {
           Text('文件大小:')
             .fontSize(14)
@@ -5472,12 +5517,13 @@ export struct LocalMusic {
           onSeekAction: (position: number) => { // 滑动歌词触发seek定位回调
             if(!this.isPlaying){
               this.startPlayOrResumePlay()
+            }else{
+              this.isSeekTo = true;
+              this.mDestroyPage = false;
+              this.showLoadIng();
+              this.seekTo(position + "");
+              this.isSeekTo = false;
             }
-            this.isSeekTo = true;
-            this.mDestroyPage = false;
-            this.showLoadIng();
-            this.seekTo(position + "");
-            this.isSeekTo = false;
             return true
           }
         })

+ 10 - 1
entry/src/main/ets/viewmodel/VideoItem.ets

@@ -37,6 +37,15 @@ export class VideoItem  {
   fileName?: string;//音乐文件的真实文件名称
   lastPlayed?:Date;
 
+  duration?:string//时长
+  mimeType?:string//类型
+  sampleRate?:string//音频的采样率单位为Hz
+  trackCount?:string//轨道数量
+  lastPlayedStr?:string;//最后播放时间
+  playCount?:number//播放次数
+  lyricContent?:string//歌词内容
+
+
 
   constructor(name: string, id: string, filePath: string, type:number,videoSize:number,cTime: string,pixelMap?: image.PixelMap,
     size?: string,pixelMapPath?: string,artist?: string,album?: string,fileName?: string, lastPlayed?:Date) {
@@ -60,7 +69,7 @@ export class VideoItem  {
     this.album = album;
     this.fileName = fileName;
     this.lastPlayed = lastPlayed;
-
+    this.playCount = 0
 
   }
 }