HarmonyOS 鸿蒙Next 录音音频之后 如何拿到音频文件的内存路径

HarmonyOS 鸿蒙Next 录音音频之后 如何拿到音频文件的内存路径

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;

}

}

相关推荐

川崎全部售价一览表
365体育怎么打不开网址

川崎全部售价一览表

📅 07-28 👁️ 3725
为什么gif保存以后不能动了
365bet足球即时比分网

为什么gif保存以后不能动了

📅 07-04 👁️ 8074
当前位置首页>行业知识> pc材料的密度
365bet足球即时比分网

当前位置首页>行业知识> pc材料的密度

📅 07-13 👁️ 5109