0

How do you record an audio in a view and getting the saved audio file after popping out in the parent view?

I am using embedded navigation controller in storyboard.

I have this code in my child view.

NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *docsDir = [dirPaths objectAtIndex:0];

tempFilePath = [NSURL fileURLWithPath:[docsDir stringByAppendingPathComponent:[NSString stringWithFormat: @"record.%@", @"caf"]]];


NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];


audioRecorder = [[ AVAudioRecorder alloc] initWithURL:tempFilePath settings:recordSetting error:nil];
[audioRecorder setDelegate:self];

[audioRecorder prepareToRecord];

[audioRecorder record];

Now, how am I gonna get that in my parent controller?

4

2 回答 2

0

您可以创建一个单例音频控制器类来进行录制,并将该音频控制器传递给每个需要使用音频的视图控制器(录制、播放等)

于 2012-04-27T13:48:49.403 回答
0

如果您有一个视图控制器录制音频,则该视图控制器应在音频被关闭之前保存音频。

你应该把它保存到一个一致的地方(例如一个缓存目录,一个文档目录,等等)。如果你给它一个可预测的文件名,你可以让你的父视图控制器轻松找到它,以便在需要时再次加载它。

或者,您可以从导航控制器获取父视图控制器的句柄,并传递写入输出音频数据(或 URL)的路径或原始音频NSData对象本身。这完全取决于您如何实现代码。

于 2012-04-27T10:47:31.667 回答