2014-05-10 40 views
0

我使用AVAudioRecorder它順利拍攝,我可以播放或得到保存的文件我使用下面的代碼來初始化AVAudioRecorderAVAudioRecorder指定

NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys: 
          [NSNumber numberWithInt:kAudioFormatMPEG4AAC], AVFormatIDKey, 
          [NSNumber numberWithInt:AVAudioQualityLow], AVEncoderAudioQualityKey, 
          [NSNumber numberWithInt:16], AVEncoderBitRateKey, 
          [NSNumber numberWithInt: 1], AVNumberOfChannelsKey, 
          [NSNumber numberWithFloat:16000], AVSampleRateKey, 
          nil]; 

NSArray *searchPaths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentPath_ = [searchPaths objectAtIndex: 0]; 
NSString *pathToSave = [documentPath_ stringByAppendingPathComponent:[self dateString]]; 

self.pathfinal = pathToSave; 
NSURL *url = [NSURL fileURLWithPath:pathToSave]; 
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error]; 

if (!recorder) 
{ 
    return NO; 
} 
recorder.delegate = self; 
recorder.meteringEnabled = YES; 
if (![recorder prepareToRecord]) 
{ 
    return NO; 
} 

if (![recorder record]) 
{ 
    return NO; 
} 

錄製音頻,但我的一些客戶是當它們停止記錄(它將保存在磁盤上的步驟)時,它不會保存創建文件的任何內容,但每次記錄時都沒有數據。

但是,當使用不同的iPhone它不是一個問題。 iPhone有2GB可用硬盤空間。任何想法可能是什麼原因造成的?

+1

[AVAudioRecorder不能在iPhone 5S上工作]的可能的重複(http://stackoverflow.com/questions/19192316/avaudiorecorder-not-working-on-iphone-5s) – Howli

回答

1

在我的情況下,只需嘗試而不是使用AVEncoderBitRateKey將解決問題。

看到這個question

+0

謝謝,我會研究它 – Hassy

1

AVEncoderBitRateKey不需要記錄AAC格式的音頻。 AAC是一種低質量的錄音。 AVEncoderBitRateKey用於錄製高質量的音頻。