I wonder if any of you could help with this problem. The following code is trying to access an audio file ‘4sSweepReverse.wav’ at a path location determined and contained within the char *path. This code works absolutely fine when run in the simulator, but does not work when it is run on the iphone?
//print out the file path
NSLog(@"FilePath: ");
NSLog(filePath);
//Cast filePath from NSString, to Char array pointer. Needed to get reference to audio file.
const char *path = [filePath cStringUsingEncoding:[NSString defaultCStringEncoding]];
//get a ref to the audio file, need one to open it
CFURLRef audioFileURL = CFURLCreateFromFileSystemRepresentation (NULL, (const UInt8 *) path, strlen (path), false);
//open the audio file
OSStatus result = AudioFileOpenURL (audioFileURL, 0x03, kAudioFileWAVEType, &mAudioFile);
//were there any errors reading? if so deal with them first
if (result != noErr) {
NSLog([NSString stringWithFormat:@"Could not open file: %s", filePath]);
packetCount = -1;
}
I know the path contained within the file is correct. The path on the simulator is
/Users/sam2/Library/Application Support/iPhone Simulator/4.2/Applications/A355770A-6942-4E1F-BB8D-8A1B1906B42C/audioRecorder.app/4sSweepReverse.wav
And the path on the iPhone is
/var/mobile/Applications/2273E045-0A63-439E-A6AC-FD85CD30F7F2/audioRecorder.app/4sSweepReverse.wav
But when debugging the application running on the iPhone i get a -43 error (or File not found) ?
If anyone can help that would be awesome!
Sam
Wow, i feel like a bit of an idiot now! Thanks for all your suggestions guys, turns out that the iPhone was finding the file, but I was opening it with the permission flags ‘0x03’ which is read/write permissions, and obviously as a resource I can only access it with ‘0x01’ read only permissions.
Here is the correct line of code:
Once again, thanks for all your help!!