我正在使用AVAudiofoundation进行音频录制,音频正在正确存储和播放,但是我的问题是我必须录制多个音频,并且我必须在表中显示它,现在我只得到一个URL地址。请帮助我找到解决方案。
此按钮显示为暂停录音,我想在这里我想为我的问题做些事情
- (IBAction)recordPauseTapped:(id)sender
{
// Stop the audio player before recording
if (player.playing)
{
[player stop];
}
if (!recorder.recording)
{
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:YES error:nil];
// Start recording
[recorder record];
[recordPauseButton setTitle:@"Pause" forState:UIControlStateNormal];
}
else
{
// Pause recording
[recorder pause];
[recordPauseButton setTitle:@"Record" forState:UIControlStateNormal];
}
[stopButton setEnabled:YES];
[playButton setEnabled:NO];
}
此按钮用于停止录制
- (IBAction)stopTapped:(id)sender
{
[recorder stop];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setActive:NO error:nil];
NSString *urr=[recorder.url absoluteString];
[recordeddata addObject:urr];
}
此按钮用于播放录制的音频
- (IBAction)playTapped:(id)sender {
if (!recorder.recording)
{
player = [[AVAudioPlayer alloc] initWithContentsOfURL:recorder.url error:nil];
[player setDelegate:self];
[player play];
[_tableview reloadData];
}
}
您仅使用一个文件路径来初始化录音机,因此一次只能保存一个音频
NSMutableArray *pathComponents = [NSMutableArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
@"MyAudioMemo.m4a",
nil];
使这个名字MyAudioMemo.m4a
充满活力,
当您想录制新音频时
- (int)numberOfFilesInDocPath
{
NSString *docPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSFileManager *filemgr = [NSFileManager defaultManager];
NSArray *filelist= [filemgr directoryContentsAtPath: docPath];
int count = [filelist count];
return count;
}
- (void)recordNewAudioWithFileName
{
int numberOfFiles = [self numberOfFilesInDocPath];
NSString *newFileName = [NSString stringWithFormat:@"MyAudioMemo_%d.m4a",numberOfFiles];
NSMutableArray *pathComponents = [NSMutableArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
newFileName,
nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
// Setup audio session
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
// Define the recorder setting
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
// Initiate and prepare the recorder
recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:nil];
recorder.delegate = self;
recorder.meteringEnabled = YES;
[recorder prepareToRecord];
}
对于整个实施,请检查此
希望这可以帮助,
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句