2013-08-26 130 views
0

我設法設置AVAudiorecorder進行錄製,但我想將錄製文件保存在文檔目錄中以稍後收聽。我嘗試這樣做:保存AVAudioRecording路徑

- (void) audioRecorderDidFinishRecording:(AVAudioRecorder *)avrecorder successfully:(BOOL)flag{ 

ButtonStopRecording.hidden = YES; 

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"audioFile.ext"]; // Where ext is the audio format extension you have recorded your sound 
[avrecorder.data writeToFile:filePath atomically:YES]; 

} 

但在

avrecorder.data 

錯誤我該如何解決這個問題?

+0

現在您必須知道,如果您發佈有關錯誤的問題,則應在問題中包含完整的錯誤。 – rmaddy

回答

0

嘗試訪問使用

avrecorder.url 

文件假定您已經正確設置你的刻錄機,當你開始record

這樣的事情...

NSString *temnpVoiceFile = [NSString pathWithComponents:[NSArray arrayWithObjects:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject], @"tempVoice.caf", nil]]; 

// We need to update the file generator 
NSURL *soundFileURL = [NSURL fileURLWithPath:temnpVoiceFile]; 

NSError *error = nil; 

// Instantiate an audio recorder. 
self.audioRecorder = [[[AVAudioRecorder alloc] initWithURL:soundFileURL settings:_recordSettings error:&error] autorelease]; 
NSAssert1(!error, @"error creating audio file = %@", error); 

BOOL fileSuccess = [_audioRecorder prepareToRecord]; 

NSAssert(fileSuccess, @"audio recorder could not be prepared."); 
[_audioRecorder record]; 

讓我知道你是否需要更多信息。

0

沒有AVAudioRecorder的數據屬性。當您初始化AVAudioRecorder時,您只需設置位置以保存錄制的音頻。設置錄像機時,只需將其設置到文檔目錄即可。

退房蘋果文檔上AVAudioRecorder

0
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"audioFile.ext"]; // Where ext is the audio format extension you have recorded your sound 
NSData *data=[NSData dataWithContentsOfURL:avrecorder.url]; 
    [data writeToFile:soundFilePath atomically:YES]; 
[data writeToFile:filePath atomically:YES]; 

我認爲這會對您有所幫助。