【问题标题】:Cannot find file generated by iPhone simulator找不到 iPhone 模拟器生成的文件
【发布时间】:2011-04-14 10:36:27
【问题描述】:

如果这与 my previous question 重复,我深表歉意,但这让我有点生气。

为了找出 iPhone 模拟器存储文件的位置,我使用 Speak Here 项目来录制我的声音并将其保存到文件中。由于模拟器能够播放录音必须在某处有一个文件,但我无法找到。我已经尝试了所有方法,包括使用终端命令 locate(在使用 sudo /usr/libexec/locate.updatedb 之后)。有什么帮助吗?

【问题讨论】:

    标签: iphone cocoa-touch file filesystems simulator


    【解决方案1】:

    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/

    【讨论】:

      【解决方案2】:

      #define DOCUMENTS_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]

      -(void) 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];
      

      }

      -(void) 停止录制 { NSLog(@"stopRecording"); [录音机停止]; NSLog(@"停止"); }

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-05
      • 1970-01-01
      • 2012-02-22
      • 2010-12-24
      • 2012-02-03
      • 2011-06-08
      • 2015-01-08
      • 1970-01-01
      相关资源
      最近更新 更多