Reputation: 1687
I have an app that uses .aupreset
files along with .wav
samples to define instruments that are loaded into an AUSampler audio unit.
The .aupreset
files reference the .wav
files with absolute paths. As described in Technical Note 2283, if the audio files cannot be found at the original path, then the system searches in the Bundle Directory, NSLibraryDirectory, NSDocumentsDirectory, and NSDownloadsDirectory, in that order.
I can get the instruments working in the app bundle, but now I'm trying to support downloaded instruments. If I put the content in <NSLibraryDirectory>/Sounds/
, the AUSampler can't find the .wav
samples, but if I put it in <NSDocumentsDirectory>/Sounds/
, it works. I don't want to clutter the Documents directory with the instruments though, as that folder shows up in iTunes.
This is the error printed by the AUSampler:
09:27:25.251 ERROR: [0x19989c310] 372: Failed to locate sample 'file:///Sounds/trance/square-lead/Square-12000Hz.wav'
Also, I can't even create a directory at the NSDownloadsDirectory location - I just get an Operation not permitted error.
Has anyone successfully loaded samples from the Library before?
(This is on iOS 8.)
Upvotes: 0
Views: 346
Reputation: 1687
I received this explanation from an Apple Engineer:
It turns out the documentation for this is incorrect for iOS: AUSampler will only look in NSDocumentDirectory and the NSDownloadsDirectory in addition to the bundle. These are the recommended locations for storing application-specific data, if you aren't going to store it in the bundle, or you wish to enable users to add additional content to the app.
For OSX, the NSLibraryDirectory is also available.
From my own testing, however, you can't use the NSDownloadsDirectory either, as trying to create the directory returns an error ("The operation couldn’t be completed. Operation not permitted"). So it would appear that the only options on iOS are loading from the bundle or from the Documents directory.
This isn't ideal when you also want to enable iTunes File Sharing for other content, so I did think of another workaround: put the content in an arbitrary location, and when loading the .aupreset file, rewrite all the file references to refer to that location before setting it on the Audio Unit.
Upvotes: 1
Reputation: 4955
Yes, you can definitely load samples from the Library directory. I thought you had to create the library directory, but I was mistaken. It is the Application Support directory I was thinking of.
Upvotes: 0