我想知道你们中是否有人可以帮助解决这个问题。以下代码尝试在确定并包含在char *路径中的路径位置访问音频文件“4sSweepReverse.wav”。在模拟器中运行时,此代码可以正常工作,但在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;
}
我知道文件中包含的路径是正确的。模拟器上的路径是
/Users/sam2/Library/Application Support/iPhone Simulator/4.2/Applications/A355770A-6942-4E1F-BB8D-8A1B1906B42C/audioRecorder.app/4sSweepReverse.wav
iPhone上的路径是
/var/mobile/Applications/2273E045-0A63-439E-A6AC-FD85CD30F7F2/audioRecorder.app/4sSweepReverse.wav
但是当调试在iPhone上运行的应用程序时,我得到-43错误(或找不到文件)?
如果有人能提供帮助那就太棒了! 萨姆
答案 0 :(得分:3)
以下是正确的代码行:
//open the audio file
OSStatus result = AudioFileOpenURL (audioFileURL, 0x01, kAudioFileWAVEType, &mAudioFile);
再次感谢您的帮助!!
答案 1 :(得分:1)
项目中的资源是否完全命名为“4sSweepReverse.wav”而不是(例如)“4ssweepreverse.wav”(全部小写)?
设备文件系统区分大小写,但模拟器不是 请参阅Apple QA1697:Why doesn't my device load a file that loads fine in the Simulator?
答案 2 :(得分:0)
您可能想要尝试的一些事项 -