|
@@ -73,7 +73,7 @@ import { secondToTime } from '../common/util/CommUtils';
|
|
|
import { CommonConstants2 } from '../common/util/CommonConstants2';
|
|
import { CommonConstants2 } from '../common/util/CommonConstants2';
|
|
|
import { hilog } from '@kit.PerformanceAnalysisKit';
|
|
import { hilog } from '@kit.PerformanceAnalysisKit';
|
|
|
import { LazyDataSource } from '../common/util/LazyDataSource';
|
|
import { LazyDataSource } from '../common/util/LazyDataSource';
|
|
|
-import MediaTable from '../common/util/MediaTable';
|
|
|
|
|
|
|
+import MediaTable, { MediaMetadata } from '../common/util/MediaTable';
|
|
|
import NetAxiosUtil from '../common/util/NetAxiosUtil';
|
|
import NetAxiosUtil from '../common/util/NetAxiosUtil';
|
|
|
import ImageUtils from '../common/util/ImageUtils';
|
|
import ImageUtils from '../common/util/ImageUtils';
|
|
|
import { ringtone } from '@kit.RingtoneKit';
|
|
import { ringtone } from '@kit.RingtoneKit';
|
|
@@ -630,17 +630,40 @@ export struct LocalMusic {
|
|
|
|
|
|
|
|
this.songList = PreferencesUtil.getSync('LastMusicList', []) as Array<VideoItem>
|
|
this.songList = PreferencesUtil.getSync('LastMusicList', []) as Array<VideoItem>
|
|
|
this.currentSong = PreferencesUtil.getSync('LastMusicInfo', undefined) as VideoItem
|
|
this.currentSong = PreferencesUtil.getSync('LastMusicInfo', undefined) as VideoItem
|
|
|
|
|
+
|
|
|
|
|
+ // 打印加载的当前歌曲信息,用于调试
|
|
|
|
|
+ if (this.currentSong) {
|
|
|
|
|
+ console.info(`加载歌曲信息 - 采样率: ${this.currentSong.sampleRate}, MIME类型: ${this.currentSong.mimeType}`);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (ArrayUtil.isEmpty(this.songList)) {
|
|
if (ArrayUtil.isEmpty(this.songList)) {
|
|
|
this.songList = this.getCurFileList()
|
|
this.songList = this.getCurFileList()
|
|
|
} else {
|
|
} else {
|
|
|
- this.curIndex = Utility.getIndexFromList(this.songList, this.currentSong.filePath)
|
|
|
|
|
|
|
+ this.curIndex = Utility.getIndexFromList(this.songList, this.currentSong?.filePath || '')
|
|
|
}
|
|
}
|
|
|
if (ArrayUtil.isNotEmpty(this.songList)) {
|
|
if (ArrayUtil.isNotEmpty(this.songList)) {
|
|
|
this.sonDataSource.pushArrayData(this.songList)
|
|
this.sonDataSource.pushArrayData(this.songList)
|
|
|
if (this.currentSong === undefined) {
|
|
if (this.currentSong === undefined) {
|
|
|
-
|
|
|
|
|
this.currentSong = this.songList[0]
|
|
this.currentSong = this.songList[0]
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 如果当前歌曲缺少必要信息,尝试从数据库中重新加载
|
|
|
|
|
+ if (this.currentSong && (!this.currentSong.sampleRate || !this.currentSong.mimeType)) {
|
|
|
|
|
+ this.table.queryByFilePath(this.currentSong.filePath, (result: VideoItem[]) => {
|
|
|
|
|
+ if (result && result.length > 0) {
|
|
|
|
|
+ // 更新当前歌曲对象,手动复制属性
|
|
|
|
|
+ if (this.currentSong) {
|
|
|
|
|
+ const dbItem = result[0];
|
|
|
|
|
+ this.currentSong.sampleRate = dbItem.sampleRate;
|
|
|
|
|
+ this.currentSong.mimeType = dbItem.mimeType;
|
|
|
|
|
+ this.currentSong.duration = dbItem.duration;
|
|
|
|
|
+ this.currentSong.trackCount = dbItem.trackCount;
|
|
|
|
|
+ console.info(`从数据库更新歌曲属性 - 采样率: ${dbItem.sampleRate}, MIME类型: ${dbItem.mimeType}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
this.videoUrl = this.currentSong.filePath
|
|
this.videoUrl = this.currentSong.filePath
|
|
|
this.name = this.currentSong.name
|
|
this.name = this.currentSong.name
|
|
|
this.cover = this.currentSong.pixelMapPath
|
|
this.cover = this.currentSong.pixelMapPath
|
|
@@ -3582,6 +3605,9 @@ export struct LocalMusic {
|
|
|
|
|
|
|
|
if (ArrayUtil.isNotEmpty(this.songList)) {
|
|
if (ArrayUtil.isNotEmpty(this.songList)) {
|
|
|
this.isShowPlay = true;
|
|
this.isShowPlay = true;
|
|
|
|
|
+ // 显示播放界面时重新提取音频元数据
|
|
|
|
|
+ this.refreshCurrentSongMetadata();
|
|
|
|
|
+
|
|
|
let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
|
|
let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
|
|
|
this.initLyric(lyricPath);
|
|
this.initLyric(lyricPath);
|
|
|
if (FileUtil.accessSync(this.favPath)) {
|
|
if (FileUtil.accessSync(this.favPath)) {
|
|
@@ -4138,11 +4164,15 @@ export struct LocalMusic {
|
|
|
.fontSize(14)
|
|
.fontSize(14)
|
|
|
.fontColor(Color.White)
|
|
.fontColor(Color.White)
|
|
|
.margin({ left: 22 })
|
|
.margin({ left: 22 })
|
|
|
- Text(Utility.convertToKHz(this.currentSong.sampleRate))
|
|
|
|
|
|
|
+ Text(Utility.convertToKHz(this.currentSong?.sampleRate || ''))
|
|
|
.fontSize(14)
|
|
.fontSize(14)
|
|
|
.margin({ left: 10 })
|
|
.margin({ left: 10 })
|
|
|
.fontColor(Color.White)
|
|
.fontColor(Color.White)
|
|
|
.layoutWeight(1)
|
|
.layoutWeight(1)
|
|
|
|
|
+ .onAppear(() => {
|
|
|
|
|
+ console.info('音频信息:'+JSON.stringify(this.currentSong))
|
|
|
|
|
+ console.info(`音频采样率原始值: ${this.currentSong?.sampleRate}, 类型: ${typeof this.currentSong?.sampleRate}`);
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
.width('100%')
|
|
.width('100%')
|
|
|
.margin({ top: 10, bottom: 10 })
|
|
.margin({ top: 10, bottom: 10 })
|
|
@@ -4153,11 +4183,14 @@ export struct LocalMusic {
|
|
|
.fontSize(14)
|
|
.fontSize(14)
|
|
|
.fontColor(Color.White)
|
|
.fontColor(Color.White)
|
|
|
.margin({ left: 22 })
|
|
.margin({ left: 22 })
|
|
|
- Text(this.currentSong.mimeType)
|
|
|
|
|
|
|
+ Text(Utility.formatMimeType(this.currentSong?.mimeType || ''))
|
|
|
.fontSize(14)
|
|
.fontSize(14)
|
|
|
.margin({ left: 10 })
|
|
.margin({ left: 10 })
|
|
|
.fontColor(Color.White)
|
|
.fontColor(Color.White)
|
|
|
.layoutWeight(1)
|
|
.layoutWeight(1)
|
|
|
|
|
+ .onAppear(() => {
|
|
|
|
|
+ console.info(`音频MIME类型原始值: ${this.currentSong?.mimeType}, 类型: ${typeof this.currentSong?.mimeType}`);
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
.width('100%')
|
|
.width('100%')
|
|
|
.margin({ top: 10, bottom: 10 })
|
|
.margin({ top: 10, bottom: 10 })
|
|
@@ -7399,6 +7432,53 @@ export struct LocalMusic {
|
|
|
this.replayVisible = Visibility.Visible;
|
|
this.replayVisible = Visibility.Visible;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 从文件重新提取音频元数据
|
|
|
|
|
+ private async refreshCurrentSongMetadata() {
|
|
|
|
|
+ if (!this.currentSong || StrUtil.isEmpty(this.currentSong.filePath)) {
|
|
|
|
|
+ console.error('无法刷新元数据,当前歌曲或文件路径为空');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 直接从音频文件重新加载完整的元数据
|
|
|
|
|
+ console.info(`开始重新提取音频元数据: ${this.currentSong.filePath}`);
|
|
|
|
|
+ const refreshedItem = await Utility.uriGetMusicAssetsFromFile(
|
|
|
|
|
+ this.context,
|
|
|
|
|
+ this.currentSong.filePath,
|
|
|
|
|
+ CommonConstants.TYPE_LOCAL,
|
|
|
|
|
+ false
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // 只更新元数据相关字段,保留其他字段
|
|
|
|
|
+ if (this.currentSong) {
|
|
|
|
|
+ this.currentSong.duration = refreshedItem.duration;
|
|
|
|
|
+ this.currentSong.mimeType = refreshedItem.mimeType;
|
|
|
|
|
+ this.currentSong.sampleRate = refreshedItem.sampleRate;
|
|
|
|
|
+ this.currentSong.trackCount = refreshedItem.trackCount;
|
|
|
|
|
+
|
|
|
|
|
+ // 更新数据库中的记录以确保下次不需要重新提取
|
|
|
|
|
+ // 创建符合MediaMetadata接口的对象
|
|
|
|
|
+ const metadataToUpdate: MediaMetadata = {
|
|
|
|
|
+ duration: refreshedItem.duration,
|
|
|
|
|
+ mimeType: refreshedItem.mimeType,
|
|
|
|
|
+ sampleRate: refreshedItem.sampleRate,
|
|
|
|
|
+ trackCount: refreshedItem.trackCount
|
|
|
|
|
+ };
|
|
|
|
|
+ this.table.updateMediaMetadata(this.currentSong.filePath, metadataToUpdate, (success: boolean) => {
|
|
|
|
|
+ if (success) {
|
|
|
|
|
+ console.info('成功更新音频元数据到数据库');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.error('更新音频元数据到数据库失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ console.info(`刷新后的采样率: ${this.currentSong.sampleRate}, MIME类型: ${this.currentSong.mimeType}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ console.error(`刷新音频元数据失败: ${err}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private async play(url: string) {
|
|
private async play(url: string) {
|
|
|
let that = this;
|
|
let that = this;
|
|
|
that.showLoadIng();
|
|
that.showLoadIng();
|
|
@@ -7718,10 +7798,16 @@ export struct LocalMusic {
|
|
|
|
|
|
|
|
//保存最后播放的那首歌和已经对应的播放列表
|
|
//保存最后播放的那首歌和已经对应的播放列表
|
|
|
saveLastPlayList() {
|
|
saveLastPlayList() {
|
|
|
-
|
|
|
|
|
- PreferencesUtil.putSync('LastMusicInfo', this.currentSong)
|
|
|
|
|
|
|
+ // 确保所有字段都被保存,特别是sampleRate和mimeType
|
|
|
|
|
+ if (this.currentSong) {
|
|
|
|
|
+ // 打印当前歌曲的采样率和MIME类型值,用于调试
|
|
|
|
|
+ console.info(`保存歌曲信息 - 采样率: ${this.currentSong.sampleRate}, MIME类型: ${this.currentSong.mimeType}`);
|
|
|
|
|
+
|
|
|
|
|
+ // 将完整对象保存到LastMusicInfo
|
|
|
|
|
+ PreferencesUtil.putSync('LastMusicInfo', this.currentSong)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
PreferencesUtil.putSync('LastMusicList', this.songList)
|
|
PreferencesUtil.putSync('LastMusicList', this.songList)
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//添加播放历史记录
|
|
//添加播放历史记录
|
|
@@ -8956,3 +9042,4 @@ function cutPopupBuilder(dataBu: BubbleBean) {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|