当我编写此代码时,它将起作用
NSString *recordFile = [NSTemporaryDirectory() stringByAppendingPathComponent: (NSString*)inRecordFile];
NSLog(@"////////////////////////// recordFile /////////////////////");
NSLog(recordFile) ;
url = CFURLCreateWithString(kCFAllocatorDefault, (CFStringRef)recordFile, NULL);
// create the audio file
XThrowIfError(AudioFileCreateWithURL(url, kAudioFileCAFType, &mRecordFormat, kAudioFileFlags_EraseFile,
&mRecordFile), "AudioFileCreateWithURL failed");
CFRelease(url);
但是当我将recordFile更改为这样时
NSString* Dpath ;
NSArray * paths;
// Build the Directory
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
Dpath = [paths objectAtIndex:0];
Dpath = [DICOMpath stringByAppendingPathComponent:@"YYYYYYYYYYYY"];
Dpath = [DICOMpath stringByAppendingPathComponent:[FirstDirectory stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]] ;
Dpath = [DICOMpath stringByAppendingPathComponent:[SecondtDirectory stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]];
Dpath = [DICOMpath stringByAppendingPathComponent:@"XXX"];
NSString *recordFile = [Dpath stringByAppendingPathComponent:inRecordFile];
我在控制台中看到消息 AudioFileCreateWithURL failed,我的代码有什么问题,确定我在第二个代码中使用的路径存在,并且工作,inRecordFile 是 caf 文件名