iOS : include audio files in an app, in its sandbox directory


#1

What would be the way to include some soundfiles in the project resources so they can be found, once the app launched, in the sandbox Documents folder by the FileBrowserComponent ?


#2

This is something I could finally do, by getting the proper info.
When we add a sound in the XCode resources, it is put by default at the same level as the executable file :

/var/containers/Bundle/Application/GDF32FD-lotsOfNumbers-Etc/AudioPlayback.app/AudioPlayback

The path for my audio file created with the function below :
File audioFile = File::getSpecialLocation (File::currentExecutableFile).getChildFile (String(“iambe.wav”));

gives this as a full path name :
/var/containers/Bundle/Application/GDF32FD-lotsOfNumbers-Etc/AudioPlayback.app/AudioPlayback/iambe.wav

So, the file browser can find the audio file and play it.
( Of course, up to me to put the file in a more appropriate folder )


#3

This has been helpful for me when trying to figure this out:

  1. The iOS closed File System (aka sandbox)
    https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html

  2. And this thread helped me get started:
    Sandboxed ios app "Documents" folder location?

You can ofcourse set a FileBrowser to the right path and use its method for dragging/clicking to handle the files.


#4

Yes, I went through these steps.
However, when I try to bypass the fileChooser, creating the file in JUCE according to the place where it is supposed to reside, and then ask if it exists, it says NO. Despite that I can find it if I open the path given by getFullPathName, when run by the Simulator :

    formatManager.registerBasicFormats();      
    audioFile = File::getSpecialLocation (File::currentExecutableFile).getChildFile (String("iambe.wav"));
    String path = audioFile.getFullPathName();
    std::cout<<"path = "<<path<<"exists : "<<audioFile.exists()<< "\n";

#5

So I tried a basic text loading example. I found that I could reach the enclosed file by invocating the following path : (compiled for OSX)
myFile = File::getSpecialLocation (File::currentApplicationFile).getChildFile (String(“Contents/Resources/truc.txt”));
… BUT for iOS I still can not get the file :
myFile = File::getSpecialLocation (File::currentApplicationFile).getChildFile (String(“truc.txt”));

I saw also the following post which is interesting as well, but not yet the answer :


#6

This isn’t an answer directly, but this really helped me figure out where those files that show up as Xcode Resources actually appear on iOS:

#if JUCE_IOS
    Array<File> results;
    File::getSpecialLocation( File::SpecialLocationType::currentApplicationFile).findChildFiles(results, File::findFilesAndDirectories, true);
    for( auto& result : results )
    {
        DBG( "result: " << result.getFullPathName() );
    }
#endif

sure enough, it gave me everything I needed to know about where the Xcode Resources were actually located on iOS compared to OS X!