0

I have a view responsible for recording audio. How can i record several audios and show them in a table view? I'm trying to use docs directory to save the recorded audios:

NSArray *folders = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

NSString *documentsFolder = [folders objectAtIndex:0];

NSString *recordedAudio = [documentsFolder stringByAppendingPathComponent:newAudio];

newAudio is a string that contains new audio name typed by the user with the suffix .m4a. To retrieve the saved audios i'm trying something like this:

NSArray *folders = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsFolder = [folders objectAtIndex:0];

NSArray *folderContents = [[NSArray alloc] initWithContentsOfFile:documentsFolder];

I expected folderContents would have all the audios stored at documentsFolder so a could load my table, but its count is 0. I'm new in docs directory, probably i'm missing something, or doing all wrong.

What is wrong, or there is another way to accomplish that?

douglasd3
  • 761
  • 2
  • 10
  • 27
  • 1
    This will return you the string or path not the array.. – Abhishek Jun 29 '12 at 14:55
  • More info [here](http://stackoverflow.com/questions/6821517/save-an-image-to-application-documents-folder-from-uiview-on-ios). – Dima Jun 29 '12 at 15:38

1 Answers1

1

You are getting the contents of the documents directory incorrectly. This is the right way:

NSArray *folderContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsFolder error:nil];

Documents is not a file, it is a folder.

edit: This is how you save a file

Assuming you have an NSData object such as

NSData *audioData = ...; // initialiazed with your recording

After you create your recordedAudio string, which is actually just the filename you want to write to (should probably called audioPath or something), you need to add this:

[audioData writeToFile:recordedAudio atomically:YES];

Dima
  • 23,484
  • 6
  • 56
  • 83