我正在使用AudioFileOpenURL来访问音频文件。它在我的设备上工作正常,但不在模拟器中。这是抛出错误的地方:
XThrowIfError(AudioFileOpenURL (sndFile, kAudioFileReadPermission, 0/*inFileTypeHint*/, &mAudioFile), "can't open file");
任何可能的想法为什么会这样?
编辑1
以下是我在模拟器上打印sndFile然后在设备上打印:
SIMULATOR
2011-04-13 12:20:10.259 iMC[51887:207] CreateQueueForFile /var/folders/u6/u6pKbm2MFriwajkdt-OQME+++TI/-Tmp-/LoopExtended.wav
2011-04-13 12:20:10.322 iMC[51887:207] sndFile file://localhost/var/folders/u6/u6pKbm2MFriwajkdt-OQME+++TI/-Tmp-/LoopExtended.wav
Error: can't open file (-43)
2011-04-13 12:20:10.323 iMC[51887:207] URL: /var/folders/u6/u6pKbm2MFriwajkdt-OQME+++TI/-Tmp-/LoopExtended.wav
DEVICE
2011-04-13 12:21:07.829 iMC[3061:307] CreateQueueForFile /private/var/mobile/Applications/16194CBB-F0B3-4D39-9655-8FD67C247D74/tmp/LoopExtended.wav
2011-04-13 12:21:07.846 iMC[3061:307] sndFile file://localhost/private/var/mobile/Applications/16194CBB-F0B3-4D39-9655-8FD67C247D74/tmp/LoopExtended.wav
2011-04-13 12:21:07.859 iMC[3061:307] URL: /private/var/mobile/Applications/16194CBB-F0B3-4D39-9655-8FD67C247D74/tmp/LoopExtended.wav
编辑2
void AQPlayer::CreateQueueForFile(CFStringRef inFilePath)
{
// printf("CreateQueueForFile called \n ");
NSString *local_recordFilePath_NSString = (NSString *)inFilePath;
NSLog(@"CreateQueueForFile %@", local_recordFilePath_NSString );
CFURLRef sndFile = NULL;
try {
if (mFilePath == NULL)
{
mIsLooping = false;
sndFile = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, inFilePath, kCFURLPOSIXPathStyle, false);
if (!sndFile) { printf("can't parse file path\n"); return; }
NSLog(@"sndFile %@", sndFile);
XThrowIfError(AudioFileOpenURL (sndFile, kAudioFileReadPermission, 0/*inFileTypeHint*/, &mAudioFile), "can't open file");
UInt32 size = sizeof(mDataFormat);
// printf("SIZE %i\n ", size);
XThrowIfError(AudioFileGetProperty(mAudioFile,
kAudioFilePropertyDataFormat, &size, &mDataFormat), "couldn't get file's data format");
mFilePath = CFStringCreateCopy(kCFAllocatorDefault, inFilePath);
}
SetupNewQueue();
}
catch (CAXException e) {
char buf[256];
fprintf(stderr, "Error: %s (%s)\n", e.mOperation, e.FormatError(buf));
}
if (sndFile)
CFRelease(sndFile);
}
编辑3
CFStringRef local_recordFilePath;
local_recordFilePath = (CFStringRef)[NSTemporaryDirectory() stringByAppendingPathComponent: @"LoopExtended.wav"];
player->CreateQueueForFile(local_recordFilePath);
答案 0 :(得分:1)
请改用它。 (的修订版强>)
CFStringRef local_recordFilePath;
local_recordFilePath = (CFStringRef)[[[NSBundle mainBundle]resourcePath] stringByAppendingPathComponent: @"LoopExtended.wav"];
player->CreateQueueForFile(local_recordFilePath);
问题是NSTemporaryDirectory()它返回操作系统路径,它可以用于MacOS应用程序而不是iOS。
谢谢,