views:

893

answers:

3

I am new to writing iPhone apps, but I have an idea for one. The only problem is that the app I want to write will require a ton of very tiny sound files. I want to organize everything in a hierarchy of folders in the app, but allow the user to add more sounds later, possibly from the music collection or something. Basically, the user needs to be able to add sound files, but the only way I see to have sound files in the app are if they are in the binary app.

Is anyone familiar with setting up an iPhone app that can access sound or media files from outside the iPhone app?

+2  A: 

You can definitely do that. Start reading this document to get familiar with iPhone's audio and video APIs.

You can write all sorts of files into the phone's file system to store the sound files later.

Pablo Santa Cruz
ok, so I can WRITE to files outside of the app, but can I read them? So if I had a microphone I could record something and put it in a special folder, say I want to boot up the iPhone app and load a bunch of sound files for my app. Can I use a separate folder to keep those files to read?
wlindner
Yes. You can definitely do that. You could record a voice message and store it on the iPhone's file system, and then use some API to play it.
Pablo Santa Cruz
Ok, so what if I don't want to record to a special separate folder. What if I just want to have a folder that I have manually put sound files into on my iPhone hard drive, then the iPhone app always looks in that folder and can use those files in the iPhone app.
wlindner
How are you planning to put the files manually into the mentioned folders?
Pablo Santa Cruz
It depends on my options. I want a folder that I can put sound files into as the dev, but also let users add more files that will then be used in the app. I guess it would be fine if only I could put a hierarchy of files in the resource folder, just as long as it's not all in the root of the app.
wlindner
I want the app to be able always look in a hardcoded folder, but have the contents be dynamic. Then index the information in the hardcoded according to a pattern. So (hardcoded folder)"Sounds"/( dynamic subfolder)"woof"/(dynamic snd files){"woof-1.mp3","woof-2.mp3"}
wlindner
I think you should be able to do that. As long as both folders are inside your app's folder, you can read/write whatever you need to in them. That includes, a folder for your pre-existing content (hardcoded) and a folder for the dynamic (user generated) content. Hope it helps.
Pablo Santa Cruz
cool, I'll start pursuing the APIs and the link you sent me. I guess I was just trying to make sure I wasn't totally wasting my time =).
wlindner
Good luck with your app!
Pablo Santa Cruz
A: 

You can't access files outside of your iphone app folder.

CiNN
What if you have a folder set up in "Resources" can you set up a folder hierarchy in there that the iPhone app could look in every time it starts up. I guess that would mean the user could not modify that folder though.
wlindner
you can do anything in your app folder
CiNN
+3  A: 

You can access files from outside your app bundle, it simply has to be in the document folder associated to your application.

Here is an example for fopening a file in the document folder (I code in Objective-C++)

FILE *fopenForDocument(std::string fileName, const char *mode) {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    std::string s=[documentsDirectory cStringUsingEncoding:NSASCIIStringEncoding];
    s+="/"+fileName;
    FILE *file = fopen(s.c_str(),mode);
    if (file==NULL) {
     //LOG("failed to open file %s",fileName.c_str());
    }
    //LOG(s.c_str());
    return file;
}

In your case, the sounds that come with your application must be in the app bundle, and the sounds your users will later add must be located in the document folder.

Jyaif