Read the original article:HarmonyOS Audio Recording: Why Your AudioCapturer Files Won't Play
Context
According to the official demo: https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V13/using-audiocapturer-for-recording-V13
The locally recorded file cannot be played, and changing it to MP3 format doesn't work either.
Description
AudioCapturer is an audio capturer used for recording PCM (Pulse Code Modulation) audio data. It's suitable for developers with audio development experience who want to implement more flexible recording functions. You need to use AudioRenderer, an audio renderer, for playing PCM (Pulse Code Modulation) audio data. Compared to AVPlayer, AudioRenderer allows for data pre-processing before input, making it more suitable for developers with audio development experience to achieve more flexible playback functions.
Solution
We recommend that you use AVRecorder to implement audio recording:
https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V13/using-avrecorder-for-recording-V13
https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V13/media-kit-intro-V13#avrecorder
Here's a demo that records and plays MP3 files; you can take a look: https://gitee.com/scenario-samples/avrecorder-demo
Key Takeaways
-
AudioCaptureris for recording PCM audio data and is for more advanced, flexible recording (for developers with audio experience). -
AudioRendereris for playing PCM audio data and also offers more flexibility (e.g., pre-processing) compared toAVPlayer. - For general audio recording, it's recommended to use
AVRecorderinstead, as it's simpler and designed for this purpose.
Top comments (0)