Accessing aif files as resource in a bundle?


#1

Hi all :slight_smile:

i am developing an app for iOS devices. This app is suppossed to playback a number of aif sound files that may be part of the bundle. I have problems accessing the aif files and I really dont know if I am on the right track. So far i read the “bundle” and “resources” programming guides but there is of course no connection to Juce, so… maybe somebody of you has experience with this and can point the right direction ?

What i do is including the aif files as resource into the bundle.
Then, i use this code to access the files

audioURL = CFBundleCopyResourceURL( mainBundle,CFSTR(“test1”),CFSTR(“aif”),NULL );
CFStringRef fn = CFURLGetString(audioURL);
String fileName = PlatformUtilities::cfStringToJuceString(fn);
File audioFile1(fileName);
( the I set up a AudioFormatReader, and so on…)

Fine… the url points to the right file in the .app, the .app contains the desired aif file, there is no runtime error opening and accessing the file, but at playback time there is no sound ouput at all… (using IPhone Simulator)
When i access the same aif from somewhere on my Macs filesystem, everything fine.

Well, there is surely something that I do in the wrong way…maybe i missed something… i simply dont know where to start searching for the solution… :frowning:

Regarding the resources programming guide i should be able to playback the files using

OSStatus error = AudioServicesCreateSystemSoundID (myURLRef, &mySSID);
AudioServicesAddSystemSoundCompletion (…)
AudioServicesPlaySystemSound (mySSID);
…but what i want is to playback the audio using Juce, not through some OSX or iOS system functions.

I also had a look on the Binarybuilder. The thing is that i dont want to be the aif files part of the code, but access them as files as they could easily become >100mb

Thanks for any help or comments.

regards
Rudi


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

If it’s not playing, you just need to step through everything in the debugger, and see what’s failing. Could be anywhere!

BTW it might be cleaner to write something like File::getSpecialLocation (File::currentApplicationFile).getChildFile (“resources/foobar.aiff”)


#3

it can be so easy ! Thanks, Jules ! :slight_smile:

btw… it seems the problem in my aproach was that CFBundleCopyResourceURL gives me an URL with some “%20” instead of just blanks. The File constructor would not complain but the audioFile.exists() gave me false. Replacing the %20s with blanks worked then…
But of course … getSpecialLocation(…) is much easier :wink:
Thanks again !