4

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?

4

3 回答 3

4

可以从应用程序包外部访问文件,它只需位于与您的应用程序关联的文档文件夹中。

这是在文档文件夹中打开文件的示例(我在 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;
}

在您的情况下,您的应用程序附带的声音必须在应用程序包中,并且您的用户稍后将添加的声音必须位于文档文件夹中。

于 2009-03-23T20:18:57.230 回答
2

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.

于 2009-03-23T13:49:20.223 回答
-1

您无法访问 iphone 应用程序文件夹之外的文件。

于 2009-03-23T14:05:45.630 回答