HarmonyOS 录音功能问题?

阅读 627
1 个回答

录音功能核心代码:

// 开始录制对应的流程
async startRecordingProcess() {
  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() + '.mp4', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);
    this.avConfig.url = 'fd://' + this.curFile.fd;
    // 3.配置录制参数完成准备工作
    await this.avRecorder.prepare(this.avConfig);
    // 4.开始录制
    this.textTimerController.start()
    await this.avRecorder.start();
    this.recordFlag = true;
  } catch (err) {
    console.log('startRecordingProcess' + JSON.stringify(err))
  }
}

可参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/using-avrecorder-for-recording-V5\#%E5%AE%8C%E6%95%B4%E7%A4%BA%E4%BE%8B

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进