Reputation: 6996
I'm having trouble with the
NSInvalidArgumentException nil string parameter when trying to use AudioFileCreateWithURL
The problem is, fileURL prints to NSLog
correct. I believe this is the correct format:
file://localhost/Users/me/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/1A617C0D-90CC-465C-9108-ECBCF85F075C/Documents/recording.wav
I'm guessing the __bridge conversion may be causing the problem.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString* docDir = [paths objectAtIndex:0];
NSString* file = [docDir stringByAppendingString:@"/recording.wav"];
NSURL *fileURL = [NSURL fileURLWithPath:file];
NSLog(@"%@", fileURL);
OSStatus audioErr = noErr;
audioErr = AudioFileCreateWithURL( (__bridge CFURLRef)fileURL, kAudioFileWAVEType, &asbd, kAudioFileFlags_EraseFile, &audioFile);
I am using ARC. I tried this as well:
audioErr = AudioFileCreateWithURL( (CFURLRef)CFBridgingRetain(fileURL), kAudioFileWAVEType, &asbd, kAudioFileFlags_EraseFile, &audioFile);
It caused the same exception.
Upvotes: 0
Views: 925
Reputation: 11855
Have you looked at http://lists.apple.com/archives/coreaudio-api/2010/Aug/msg00210.html? they used CFStringRef
to get it to work.
// We have to encode spaces before sending it to CFURLCreateWithString. See CFURLCreateWithString returns NULL article http://markmail.org/message/5ugub2dvdaausdvf
CFStringRef fileName = (CFStringRef) recordedFile;
CFStringRef fileNameEscaped = CFURLCreateStringByAddingPercentEscapes(NULL, fileName, NULL, NULL, kCFStringEncodingUTF8);
// Create the URL
self.url = "" (CFStringRef)fileNameEscaped, NULL);
CHECK_NIL(url);
// Create audio file
OSStatus status = AudioFileCreateWithURL(url, kAudioFileWAVEType, &format, kAudioFileFlags_EraseFile, &audioFile);
NSAssert(status == noErr, @"AudioFileCreateWithURL fails");
Upvotes: 2