DEV Community

HarmonyOS
HarmonyOS

Posted on

HarmonyOS Audio Recording: Why Your AudioCapturer Files Won't Play

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

  • AudioCapturer is for recording PCM audio data and is for more advanced, flexible recording (for developers with audio experience).
  • AudioRenderer is for playing PCM audio data and also offers more flexibility (e.g., pre-processing) compared to AVPlayer.
  • For general audio recording, it's recommended to use AVRecorder instead, as it's simpler and designed for this purpose.

Written by Taskhyn Maksim

Top comments (0)