2016-11-16 78 views

回答

0

如果您正在錄製音頻,那意味着您必須將它保存在某處,因爲它必須需要一些空間,否則您可以如何錄製?

您可以使用NSTemporaryDirectory保存文件一樣,

NSString *folderPath = NSTemporaryDirectory(); 



    NSString *soundFilePath = [folderPath 
           stringByAppendingPathComponent:[NSString stringWithFormat: @"%.0f%@", [NSDate timeIntervalSinceReferenceDate] *1000.0, @"audio.caf"]]; 

    NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath]; 

    NSLog(@"Using File called: %@",soundFileURL); 

    audioRecorder = [[ AVAudioRecorder alloc] initWithURL:soundFileURL settings:recordSetting error:&error]; 
    [audioRecorder setDelegate:self]; 
    [audioRecorder prepareToRecord]; 

以上是代碼段,這樣你的想法!

ios在需要時自動清除NSTemporaryDirectory因此它不是您擔心的問題。是的,你必須將錄製的音頻存儲在某個地方,如果你想永久保存!

您可以創建自己的目錄,可以作爲temp directory工作,您可以在需要時手動清除! (創建文件目錄記錄文件中,有目錄,並清除它時,你的任務將完成)

But you can't record without storing it!

0

想象一下,你會 - 會是更好?在RAM中保存GB的數據?聽起來不好。

如果你想保持你的可用磁盤空間,你可以做的是:

1)數據的一小部分保存到文件(即20 MB)

2)將該文件發送到後端?並在完成時將其從磁盤上刪除

3)重複過程,直到完成記錄

相關問題