2011-04-14 67 views
0

我很抱歉,如果这与my previous question重复,但这会让我有点慌乱。找不到iPhone模拟器生成的文件

在试图找出iPhone Simulator存储文件的位置时,我使用了Speak Here项目来记录我的声音并将其保存到文件中。由于模拟器能够播放记录,因此必须是某处的文件,但我无法找到该文件。我已经尝试了一切,包括使用终端命令定位(使用sudo /usr/libexec/locate.updatedb后)。任何帮助? enter image description here

回答

-1

的#define DOCUMENTS_FOLDER [NSHomeDirectory()stringByAppendingPathComponent:@ “文档”]

- (无效)的StartRecording { [自stopPlaying];

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 stop]; NSLog(@“stopped”); }

+0

没有工作。有错误-50。 – 2011-04-14 11:17:20

+0

什么是错误? – 2011-04-14 11:18:22

+0

AudioFileURLCreateWithURL error -50 which can not find in the reference:http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/AudioFileConvertRef/Reference/reference.html – 2011-04-14 11:21:02

0

SpeakHere应用程序将录制的文件存储在临时目录中。你可以找出路径及其内容与此代码:

NSString *tempPath = NSTemporaryDirectory(); 
    NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:tempPath error:nil]; 
    NSLog(@"tempPath: %@", tempPath); 
    NSLog(@"dirContents: %@", dirContents); 

在iPhone模拟器这条道路会像 /var/folders/eQ/eQdXXQoxFHmxhq85pgNA+++++TI/-Tmp-/,但在设备上,这是在你的应用程序目录的子目录。如/private/var/mobile/Applications/965A9EEF-7FBA-40F4-8A42-FE855A719D52/tmp/