ExtAudioFileOpenURL failure opening audio file residing in NSTemporaryDirectory()

283 views
Skip to first unread message

Mark Anderson

unread,
Apr 29, 2014, 7:51:06 PM4/29/14
to objectal-...@googlegroups.com
I know this was an issue for iPod files for < ios7, but I am confused as to why I can't seem to ExtAudioFileOpenURL() for a url path that resides in the NSTemporaryDirectory()?
Details are below, please help!

My app downloads small audio files from my server and stores them in the NSTemporaryDirectory(). Then I use ObjectAL to place audio in a 3D space. When I attempt to load an ALBuffer
with a url path by calling [[[OpenALManager sharedInstance] bufferFromUrl:theURL reduceToMono:mono] retain], opening the URL fails every time. This only seems to work by using a file
that resides in the [NSBundle mainBundle]. Is this in fact true? I can successfully open/play audio files with .mp3, .aif, and .caf formats, as long as the file is included in the -mainBundle.

If that is in fact the case, is there a way to successfully open an audio file using ExtAudioFileOpenURL() that is residing in the NSTemporaryDirectory() (or any other iOS file directories) and
feed it into an ALBuffer? The following gives an overview of relevant code:

// my source/buffer call:

- (void)setSourceWithSourceURL:(NSString *)urlString type:(CueType)cueType
volume:(ALfloat)vol isMono:(BOOL)mono isSFX:(BOOL)isSFX {

        ALSource *source = [self sourceForKey:cueType];

        ALBuffer *buffer = [self bufferForKey:cueType];

        if (!source) {

            source = [[ALSource source] retain];

        }

        if (!buffer) {

            NSArray *array = [urlString componentsSeparatedByString:@"/"];

            NSURL *furl = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:array.lastObject]];


            buffer = [[[OpenALManager sharedInstance] bufferFromUrl:furl reduceToMono:mono] retain];

        }

        // fails when setting buffer...

    }


The NSLog output for furl before making the -bufferFromUrl call is:

file:///private/var/mobile/Applications/08E20AF6-6333-4E24-9F12-20C6D6381C0B/tmp/4_right_turn_cue.aif


I verified that the file does in fact exist...


The -bufferFromUrl: reduceToMono: call essentially calls an internal ObjectAL -init method:


    - (id) initWithUrl:(NSURL*) urlIn reduceToMono:(bool) reduceToMonoIn {

    if(nil != (self = [super init])) {

    url = as_retain(urlIn);

    reduceToMono = reduceToMonoIn;


    OSStatus error = 0;

    UInt32 size;

    if(nil == url)

    {

    OAL_LOG_ERROR(@"Cannot open NULL file / url");

    goto done;

    }


    // Open the file

    if(noErr != (error = ExtAudioFileOpenURL((as_bridge CFURLRef)url, &fileHandle)))

    {

    REPORT_EXTAUDIO_CALL(error, @"Could not open url %@", url);

    goto done;

    }

            // ...more stuff but opening the URL fails


Once ExtAudioFileOpenURL() is called, I get the following error message:

OAL Error: -[OALAudioFile initWithUrl:reduceToMono:]: Could not open url
file:///private/var/mobile/Applications/08E20AF6-6333-4E24-9F12-20C6D6381C0B/tmp/4_right_turn_cue.aif
(error code 0x7768743f: Unknown ext audio error)

Any insights as to why this is failing to read an audio file from a file directory? Any ideas or workarounds? Any help is greatly appreciated!

Thanks,
Mark
Reply all
Reply to author
Forward
0 new messages