diff --git a/entry/src/main/ets/pages/VoiceClassify.ets b/entry/src/main/ets/pages/VoiceClassify.ets index 92fed8f5bea050645ea571b4e05b0d77a74466cf..ec4a25b5a551237a552369393cb8c6b4a8d92e60 100644 --- a/entry/src/main/ets/pages/VoiceClassify.ets +++ b/entry/src/main/ets/pages/VoiceClassify.ets @@ -6,6 +6,7 @@ import ButtomView from '../Components/BottomView'; import worker from '@ohos.worker' import mediaLibrary from '@ohos.multimedia.mediaLibrary'; import prompt from '@system.prompt'; +import MediaUtils from '../Model/MediaUtils'; @Entry @Component @@ -152,9 +153,9 @@ export struct VoiceClassify { .onClick(async () => { let nameList = item.name.split('.') - let fileAsset = await this.getSelectFileAsset(nameList[0]) + let fileAsset = await MediaUtils.getInstance().getSelectFileAsset(nameList[0]) AppStorage.SetOrCreate('isAudio', true) - AppStorage.SetOrCreate('playerSource', item.path) + AppStorage.SetOrCreate('playerSource', fileAsset.uri) AppStorage.SetOrCreate('playerName', item.name) router.push({ uri: 'pages/video_player', @@ -217,37 +218,13 @@ export struct VoiceClassify { }) } } - - - /* - * 获取选中资源 - * - *return fileAsset and fd - */ - - async getSelectFileAsset(title){ - let fileKeyObj = mediaLibrary.FileKey; - let fetchOp = { - selections: fileKeyObj.TITLE + '= ?', - selectionArgs: [title.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", - } - console.log('hans----..,,..:'+title) - - let fetchFileResult = await mediaLibrary.getMediaLibrary(globalThis.context).getFileAssets(fetchOp); - console.log('hans----..,,..'+fetchFileResult.getCount()) - - let fileAsset = await fetchFileResult.getFirstObject(); - console.log('hans----..,,..') - return fileAsset - } /* * 修改名字 * */ async renameOrTitle(newTitle) { let nameList = this.selectVoice.name.split('.') - let fileAsset = await this.getSelectFileAsset(nameList[0]) + let fileAsset = await MediaUtils.getInstance().getSelectFileAsset(nameList[0]) if (fileAsset) { fileAsset.title = newTitle//把刚改完的文件名赋给从媒体库获取的文件 fileAsset.displayName = newTitle+'.'+nameList[1] @@ -283,7 +260,6 @@ export struct VoiceClassify { } } - //重命名弹窗 @CustomDialog struct DialogExample { @@ -334,15 +310,11 @@ struct DialogExample { this.controller.close() this.action(this.name) } - - }) .backgroundColor('#fff1f6f1') } } .borderStyle(BorderStyle.Solid) - - } } }