如何解决找不到iPhone模拟器生成的文件
| 如果这是我上一个问题的重复,我深表歉意,但是这让我有些不安。 为了弄清楚iPhone模拟器在哪里存储文件,我使用了“在这里说”项目录制我的声音并将其保存到文件中。由于模拟器可以播放录制的文件,因此某处必须有一个文件,但是我找不到。我已经尝试了一切,包括使用终端命令locate(在使用sudo /usr/libexec/locate.updatedb之后)。有什么帮助吗?解决方法
SpeakHere应用程序将录制的文件存储在临时目录中。您可以使用以下代码找出路径及其内容:
NSString *tempPath = NSTemporaryDirectory();
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:tempPath error:nil];
NSLog(@\"tempPath: %@\",tempPath);
NSLog(@\"dirContents: %@\",dirContents);
在iOS模拟器中,此路径类似于
/var/folders/eQ/eQdXXQoxFHmxhq85pgNA+++++TI/-Tmp-/
,但在设备上,这是您应用程序目录中的子目录。像/private/var/mobile/Applications/965A9EEF-7FBA-40F4-8A42-FE855A719D52/tmp/
。
,#define DOCUMENTS_FOLDER [NSHomeDirectory()stringByAppendingPathComponent:@ \“ Documents \”]
-(无效)startRecording
{
[自停播放];
NSLog(@\"startRecording\");
[audioRecorder release];
audioRecorder = nil;
// Init audio with record capability
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryRecord error:nil];
NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] initWithCapacity:10];
if(recordEncoding == ENC_PCM)
{
[recordSettings setObject:[NSNumber numberWithInt: kAudioFormatLinearPCM] forKey: AVFormatIDKey];
[recordSettings setObject:[NSNumber numberWithFloat:44100.0] forKey: AVSampleRateKey];
[recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
[recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSettings setObject:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSettings setObject:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
}
else
{
NSNumber *formatObject;
switch (recordEncoding) {
case (ENC_AAC):
formatObject = [NSNumber numberWithInt: kAudioFormatMPEG4AAC];
break;
case (ENC_ALAC):
formatObject = [NSNumber numberWithInt: kAudioFormatAppleLossless];
break;
case (ENC_IMA4):
formatObject = [NSNumber numberWithInt: kAudioFormatAppleIMA4];
break;
case (ENC_ILBC):
formatObject = [NSNumber numberWithInt: kAudioFormatiLBC];
break;
case (ENC_ULAW):
formatObject = [NSNumber numberWithInt: kAudioFormatULaw];
break;
default:
formatObject = [NSNumber numberWithInt: kAudioFormatAppleIMA4];
}
[recordSettings setObject:formatObject forKey: AVFormatIDKey];
[recordSettings setObject:[NSNumber numberWithFloat:44100.0] forKey: AVSampleRateKey];
[recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
[recordSettings setObject:[NSNumber numberWithInt:12800] forKey:AVEncoderBitRateKey];
[recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSettings setObject:[NSNumber numberWithInt: AVAudioQualityHigh] forKey: AVEncoderAudioQualityKey];
}
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// getting an NSInteger
NSInteger recordID = [prefs integerForKey:@\"recordID\"];
//NSLog(@\"---- %d\",recordID);
//NSString *recordFileName = [NSString stringWithFormat:@\"%@/record%d.caf\",[[NSBundle mainBundle] resourcePath],recordID];
NSString *recordFileName = [NSString stringWithFormat:@\"%@/record%d.caf\",DOCUMENTS_FOLDER,recordID];
NSURL *url = [NSURL fileURLWithPath:recordFileName];
//NSLog(@\"path -- %@\",DOCUMENTS_FOLDER);
NSError *error = nil;
audioRecorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error];
if ([audioRecorder prepareToRecord] == YES){
[audioRecorder record];
}else {
int errorCode = CFSwapInt32HostToBig ([error code]);
NSLog(@\"Error: %@ [%4.4s])\",[error localizedDescription],(char*)&errorCode);
}
NSLog(@\"recording\");
[recordSettings release];
}
-(无效)stopRecording
{
NSLog(@ \“ stopRecording \”);
[audioRecorder停止];
NSLog(@ \“ stopped \”);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。