فهرست منبع

修复采样率等新增字段的数据接查询不到的问题

onecold 1 سال پیش
والد
کامیت
aeb831819a
3فایلهای تغییر یافته به همراه69 افزوده شده و 20 حذف شده
  1. 10 12
      entry/src/main/ets/common/util/RdbUtils.ets
  2. 54 4
      entry/src/main/ets/common/util/Utility.ets
  3. 5 4
      entry/src/main/ets/view/LocalMusic.ets

+ 10 - 12
entry/src/main/ets/common/util/RdbUtils.ets

@@ -60,7 +60,10 @@ export default class RdbUtils {
       '        lyricContent TEXT,\n' +
       '        mimeType TEXT' +
       ')',
-    columns: ['id', 'name', 'filePath','mtype', 'videoSize', 'cTime','size', 'artist', 'album','fileName','parentPath','isFav','pixelMapPath','pixelMapToString', 'duration', 'mimeType', 'trackCount', 'sampleRate', 'lastPlayedStr', 'playCount', 'lyricContent']
+    columns: ['id', 'name', 'filePath','mtype', 'videoSize', 'cTime','size', 'artist', 'album',
+      'fileName','parentPath','isFav','pixelMapPath','pixelMapToString',
+      'duration',   'sampleRate','playCount',  'lastPlayedStr', 'trackCount',
+      'lyricContent','mimeType']
   };
 
   constructor(tableName: string, sqlCreateTable: string, columns: Array<string>) {
@@ -301,29 +304,24 @@ export default class RdbUtils {
     }
   }
 
+
   query(predicates: relationalStore.RdbPredicates, callback: Function = () => {
   }) {
     if (!callback || typeof callback === 'undefined' || callback === undefined) {
       Logger.info(RdbUtils.RDB_TAG, 'query() has no callback!');
       return;
     }
-    
     if (this.rdbStore) {
-      // 使用安全的列集合查询
-      // 首先仅查询基本列(确保100%存在)
-      const safeColumns = ['id', 'name', 'filePath', 'mtype', 'videoSize', 'cTime', 
-                           'size', 'artist', 'album', 'fileName', 'parentPath', 
-                           'isFav', 'pixelMapPath', 'pixelMapToString'];
-      
-      this.rdbStore.query(predicates, safeColumns, (err, resultSet) => {
+      this.rdbStore.query(predicates, this.columns, (err, resultSet) => {
         if (err) {
-          Logger.error(RdbUtils.RDB_TAG, `query() failed, err: ${err}`);
-          callback(null);
+          Logger.error(RdbUtils.RDB_TAG, `query() failed, err:  ${err}`);
           return;
         }
-        
+        // Logger.info(RdbUtils.RDB_TAG, 'query() finished.');
         callback(resultSet);
+        resultSet.close();
       });
     }
   }
+
 }

+ 54 - 4
entry/src/main/ets/common/util/Utility.ets

@@ -132,6 +132,30 @@ export class Utility {
     return `${sampleRateKHz} KHz`;
   }
 
+  /**
+   * 格式化媒体格式类型显示
+   * @param mimeType 媒体格式类型字符串
+   * @return 格式化后的显示字符串
+   */
+  static formatMimeType(mimeType: string | undefined): string {
+    if (StrUtil.isEmpty(mimeType) || mimeType === undefined) {
+      return 'unknown';
+    }
+
+    // 从MIME类型中提取格式部分,例如 "audio/mp3" -> "MP3"
+    try {
+      const parts = mimeType.split('/');
+      if (parts.length > 1) {
+        return parts[1].toUpperCase();
+      } else {
+        return mimeType.toUpperCase();
+      }
+    } catch (err) {
+      console.error(`格式化媒体类型出错: ${err}`);
+      return 'unknown';
+    }
+  }
+
   //根据字节获取大小
   static  formatFileSize(bytes:number) {
     const units = ['Bytes', 'Kbps', 'Mbps'];
@@ -668,7 +692,8 @@ export class Utility {
             }
 
             if(StrUtil.isNotEmpty(metadata.duration)){
-              duration = DateUtil.getFormatDateStr(metadata.duration,'HH:mm:ss')
+              if(metadata.duration)
+                duration = convertSecondsToTime(metadata.duration.toString())
             }
             if(StrUtil.isNotEmpty(metadata.mimeType)){
               mimeType = metadata.mimeType
@@ -741,8 +766,13 @@ export class Utility {
 
 
 
-
-
+  private completionNum(num: number): string | number {
+    if (num < 10) {
+      return '0' + num;
+    } else {
+      return num;
+    }
+  }
 
   //根据字节获取大小
   static  formatFSize(bytes:number):string {
@@ -1207,4 +1237,24 @@ function getTypeOrder(type: number) {
     default:
       return 4; // Unknown types, if any, go last
   }
-}
+}
+
+function convertSecondsToTime(secondsStr: string): string {
+  if (!secondsStr || isNaN(Number(secondsStr))) {
+    return "00:00";
+  }
+
+  let seconds = parseInt(secondsStr, 10);
+  seconds = Math.floor(seconds / 1000);
+  const hours = Math.floor(seconds / 3600);
+  const minutes = Math.floor((seconds % 3600) / 60);
+  const secs = seconds % 60;
+
+  const formatNumber = (num: number) => num.toString().padStart(2, '0');
+
+  if (hours > 0) {
+    return `${formatNumber(hours)}:${formatNumber(minutes)}:${formatNumber(secs)}`;
+  } else {
+    return `${formatNumber(minutes)}:${formatNumber(secs)}`;
+  }
+}

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

@@ -768,7 +768,6 @@ export struct LocalMusic {
         files = result;
       }
 
-
       files.sort((a, b) => a.cTime.localeCompare(b.cTime));
       Utility.doSortListAscending(files)
 
@@ -796,7 +795,7 @@ export struct LocalMusic {
       console.info(`onecold gengxin 1: ${this.videoLocalList.length}`);
       // for (let i = 0; i < this.videoLocalList.length; i++) {
       //
-      //   console.info(`onecold gengxin 1: ${this.videoLocalList[i].pixelMapPath}`);
+      //   console.info(`onecold gengxin 1: ${this.videoLocalList[i].sampleRate}`);
       //
       // }
 
@@ -3539,7 +3538,9 @@ export struct LocalMusic {
         this.name = this.currentSong.name
         this.cover = this.currentSong.pixelMapPath
 
-
+        LogUtil.info('this.currentSong.duration ='+this.currentSong.duration)
+        LogUtil.info('this.currentSong.sampleRate ='+this.currentSong.sampleRate)
+        LogUtil.info('this.currentSongmimeType ='+this.currentSong.mimeType)
         this.startPlayOrResumePlay()
         break;
 
@@ -4153,7 +4154,7 @@ export struct LocalMusic {
             .fontSize(14)
             .fontColor(Color.White)
             .margin({ left: 22 })
-          Text(this.currentSong.mimeType)
+          Text(Utility.formatMimeType(this.currentSong.mimeType))
             .fontSize(14)
             .margin({ left: 10 })
             .fontColor(Color.White)