HarmonyOS 鸿蒙Next 录音音频之后 如何拿到音频文件的内存路径
录音音频之后 如何拿到音频文件的内存路径 不是uri路径
// 开始录制
async beginCollectVoice() {
try {
if (this.avRecorder == undefined) {
// 1.创建录制实例
this.avRecorder = await media.createAVRecorder();
}
this.setAudioRecorderCallback();
// 2.获取录制文件fd赋予avConfig里的url;参考FilePicker文档
this.curFile = fileIo.openSync(this.filesDir + '/Audio_' + new Date().getTime() + '.mp3',
fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);
this.avConfig.url = 'fd://' + this.curFile.fd;
this.soundData.file = `internal://cache/${this.curFile.name}`
// 3.配置录制参数完成准备工作
await this.avRecorder.prepare(this.avConfig);
// 4.开始录制
this.textTimerController.start()
await this.avRecorder.start();
this.recordFlag = true;
} catch (err) {
console.log(TAG, 'startRecordingProcess' + JSON.stringify(err))
}
}
// 停止录制对应的流程
async stopRecordingProcess() {
if (this.avRecorder != undefined) {
// 1. 停止录制
if (this.avRecorder.state === 'started'
|| this.avRecorder.state === 'paused') { // 仅在started或者paused状态下调用stop为合理状态切换
await this.avRecorder.stop();
}
// 2.重置
this.recordFlag = false;
await this.avRecorder.reset();
this.textTimerController.reset();
// 3.释放录制实例
await this.avRecorder.release();
this.fileNames.push([this.curFile?.name ? this.curFile?.name : '', this.totalTime])
console.info("录音列表", JSON.stringify(this.fileNames))
// 4.关闭录制文件fd
fileIo.closeSync(this.curFile)
console.info('录音文件地址', JSON.stringify(this.curFile)) // 打印结果 {}
this.avRecorder = undefined;
}
}