2

i have converted my .caf audio file to NSData object using the following line of code:

NSData *audioData = [NSData dataWithContentsOfFile:[MyRecorderFilePathURL path] options: 0 error:&err];

I am doing so to upload the binary object to a server through a web service. How do i convert audioData back to a .caf file which can be played using AVAudioPlayer?

Rohit
  • 23
  • 1
  • 4

1 Answers1

6

AVAudioPlayer has a method for playing sound from NSData object . You can use

- (id)initWithData:(NSData *)data error:(NSError **)outError method of AVAudioPlayer

Ali3n
  • 1,244
  • 6
  • 10
  • thanks. this serves the purpose! but is there a way to convert nsdata object to an audio file? – Rohit Feb 06 '12 at 10:12
  • NSData has method for this.. writeToURL:atomically: you can give file name with extension caf – Ali3n Feb 06 '12 at 11:11
  • @Ali3n this doesn't work in my scenario - http://stackoverflow.com/questions/9385705/iphone-nsdata-representation-of-audio-file-for-editing Could you please help me out! Thanks. – Paresh Masani Feb 21 '12 at 22:13
  • ...because of this - http://stackoverflow.com/questions/9394630/iphone-editing-audio-files-header-and-footer it didn't work! – Paresh Masani Feb 22 '12 at 15:47