How to play PCM data / buffer using AVAudioPlayer or AVPlayer?

How can I play PCM data / buffer only with AVAudioPlayer or AVPlayer? I know that I can play PCM data / buffer using AudioUnit / AudioQueue by passing data to the callback method. But I do not want to do this.

I searched a lot on google but couldn't find a useful answer or any sample code for this. Any help would be greatly appreciated.

+6
source share
2 answers

I answer my question if it helps someone else. After several days of tireless attempts, finally, I succeeded. Although separately. I added the wav header information on top of the RAW PCM data and saved the .wav file. Then just play the file using AVAudioPlayer or AVPlayer. Here you will get a complete code example. How to add a header (e.g. wav, wmv) with PCM data / buffer in iOS NU.

+7
source

PCM data does not determine the readable format, so AVPlayer will not be able to play it. You must save the PCM data in the audio file format that the player supports.

+1
source

Source: https://habr.com/ru/post/981727/


All Articles