9

How can i play PCM data/buffer just using AVAudioPlayer or AVPlayer ? I know, i can play PCM data/buffer using AudioUnit/AudioQueue by feeding the data into play callback method. But don't want to do this.

I have searched on google a lot but couldn't find any helpful answer or any sample code to do this. Any help would be highly appreciated.

Partho Biswas
  • 2,290
  • 1
  • 24
  • 39

2 Answers2

12

I am answering my own question if it helps someone else. After few days of tireless trying, at last i have got it working. Though in a separate way. I have added a wav header info on top of RAW PCM data and saved a file with .wav extension. Then just play the file using AVAudioPlayer or AVPlayer. Here you will get full sample code on How to add playable(such as wav,wmv) header with PCM data/buffer in iOS ou.

Community
  • 1
  • 1
Partho Biswas
  • 2,290
  • 1
  • 24
  • 39
  • Is there a way to set the AVAudioPlayer format externally and then write only the PCM samples? Android has something similar with the AudioTrack class... – Massimo Nov 30 '16 at 14:23
2

PCM data does not specify a readable format so AVPlayer will not be able to play it. You must save the PCM data into an audio file format that the player supports.

rocky
  • 3,521
  • 1
  • 23
  • 31