录音功能代码要单独封装一个类使用,应该怎么封装?https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/using-audiocapturer-for-recording-V5现在这些代码不能放到class中。
录音功能核心代码:// 开始录制对应的流程 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
录音功能核心代码:
可参考文档: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