1

I'm using CDSoundEngine to record sounds and save them in the users /Documents/ directory. It works fine...if I go to the iPad simulator's library the sounds are there...

My problem is that they do not play. It plays if I copy the soundfile to the project.

What am I missing?

 -(void) playRecording {

 //alternative approach
 //NSString *filePath = [NSURL fileURLWithPath: recorderFilePath];

 NSURL *url = [NSURL fileURLWithPath: recorderFilePath];
 NSString *filePath = [url absoluteString];

 CCLOG(@"Playing the recorded audio ... %@",filePath); //correctly displays the path (with %20 for spaces) to /Documents/recording.caf

 CDSoundEngine *sse = [[CDAudioManager sharedManager] soundEngine];

 //[sse loadBuffer:1 filePath:@"recording.caf"]; //this works if the file is added to the main project

 [sse loadBuffer:1 filePath:filePath]; //this does not work

 //[sse loadBuffer:1 filePath:@"filePath"]; //this does not work

 [sse playSound:1 sourceGroupId: 0 pitch: 2.0f pan: 0.0f gain: 1.0f loop: NO];

 }
Jim Rota
  • 1,781
  • 2
  • 16
  • 21
  • what is recorderFilePath, how is it set? I'm thinking you got the path to the user's documents folder wrong. It's not /Documents on iOS, it should look more like this: /var/mobile/Applications/2364FFA3-48BC-4206-BE9A-F58CA978EEEB/Documents … if that's not what you have, search for how to get the documents dir on SO. – CodeSmile Apr 17 '13 at 18:30
  • recorderFilePath = [[NSString stringWithFormat:@"%@/recording.caf", DOCUMENTS_FOLDER] retain]; CCLOG(@"recorderFilePath is %@",recorderFilePath) displays "recorderFilePath is /Users/jrota/Library/Application Support/iPhone Simulator/6.0/Applications/FE6AFB76-3E0C-45B7-BBAC-DEA134F3CFDE/Documents/recording.caf" When I convert it to an NSString (fileURLWithPath) it logs as "file://localhost/Users/jrota/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/FE6AFB76-3E0C-45B7-BBAC-DEA134F3CFDE/Documents/recording.caf" – Jim Rota Apr 18 '13 at 14:52
  • I have a similar/same question - in my case it's regarding SimpleAudioEngine, but it really in turn uses the same (?) CDAudioManager to find, load and play the audio. http://stackoverflow.com/questions/17713490/play-background-music-outside-of-app-bundle-using-simpleaudioengine It turned out that the class for some reason always just looks at paths relative to the bundle path. Documents folder on iOS is (this is the point) outside of the bundle path, actually one step up, so relative from Bundle path it would look like "../Documents/somefilehere.mp3". Note however that this is NOT future proof – Jonny Dec 18 '14 at 02:29
  • ... (continued) and not recommended way of specifying the path. Which is the reason I looked this up again - this one seems to have broken again... I think the bottom line is that CDAudioManager **should** allow absolute paths and should not take relative paths (only as a backwards compatible option, perhaps) – Jonny Dec 18 '14 at 02:31

0 Answers0