如何解决AudioFileOpenURL导致错误-43无法在模拟器上打开文件,但无法在设备上打开文件
|| 我正在使用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,\"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);
解决方法
改用它。 (更新)
CFStringRef local_recordFilePath;
local_recordFilePath = (CFStringRef)[[[NSBundle mainBundle]resourcePath] stringByAppendingPathComponent: @\"LoopExtended.wav\"];
player->CreateQueueForFile(local_recordFilePath);
问题是NSTemporaryDirectory(),它返回可用于MacOS应用程序而非iOS的操作系统路径。
谢谢,
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。