作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
实际上我想录制音频并存储到文档中,我找到了 FilePath 甚至附加了音频文件,但是我想将实际音频附加到该路径中,它不起作用,我在 DidFinish
中编写了该代码像这样。
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"Recording Area";
[btnRecord setBackgroundImage:[UIImage imageNamed:@"Record.png"] forState:UIControlStateNormal];
session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
audioRecorder.delegate = self;
NSDate *today = [[NSDate alloc]init];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"hh:mm:ss"];
NSString *currentTime = [dateFormatter stringFromDate:today];
NSString *outputPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
outputPath = [outputPath stringByAppendingString:[NSString stringWithFormat:@"%@.m4a",currentTime]];
NSMutableDictionary *recordDictionary = [[NSMutableDictionary alloc] init];
[recordDictionary setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordDictionary setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordDictionary setValue:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
audioRecorder = [[AVAudioRecorder alloc]initWithURL:[NSURL fileURLWithPath:outputPath] settings:recordDictionary error:nil];
audioRecorder.meteringEnabled = YES;
[audioRecorder prepareToRecord];
}
and For Recording Audio
-(IBAction)onClickRecord:(id)sender
{
if(player.playing)
{
[player stop];
}
if([[btnRecord backgroundImageForState:UIControlStateNormal]isEqual:[UIImage imageNamed:@"Record.png"]])
{
if (!audioRecorder.recording)
{
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:YES error:nil];
[audioRecorder record];
[btnRecord setBackgroundImage:[UIImage imageNamed:@"Pause.png"] forState:UIControlStateNormal];
}
}
else if([[btnRecord backgroundImageForState:UIControlStateNormal]isEqual:[UIImage imageNamed:@"Pause.png"]])
{
[audioRecorder pause];
[btnRecord setBackgroundImage:[UIImage imageNamed:@"Record.png"] forState:UIControlStateNormal];
}
}
-(IBAction)onClickSave:(id)sender
{
[audioRecorder stop];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setActive:NO error:nil];
}
- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag
{
[btnRecord setBackgroundImage:[UIImage imageNamed:@"Record.png"] forState:UIControlStateNormal];
[arrayFiles addObject:recorder.url.absoluteString];
NSLog(@"Array %@",arrayFiles);
}
最佳答案
您在初始化 AVAudioRecorder
之前设置委托(delegate)
移动audioRecorder.delegate = self;
初始化后
audioRecorder = [[AVAudioRecorder alloc]initWithURL:[NSURL fileURLWithPath:outputPath] settings:recordDictionary error:nil];
audioRecorder.meteringEnabled = YES;
audioRecorder.delegate = self;
[audioRecorder prepareToRecord];
关于ios - AVAudioRecorderDelegate 的代表没有调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36131765/
实际上我想录制音频并存储到文档中,我找到了 FilePath 甚至附加了音频文件,但是我想将实际音频附加到该路径中,它不起作用,我在 DidFinish 中编写了该代码像这样。 - (void
我的 AVAudioRecorderDelegate Interruptions 方法没有被调用。 我设置了代表。 这里可能是什么问题? tnx 最佳答案 代理是否添加到 .h 接口(interfac
我正在创建一个 iOS 应用程序,它在出现提示时而不是在按下按钮时开始录制音频。因此,我将 AVAudioRecorder 放在一个从它自己的类调用的调度程序对象中。但是,当我将 调度程序指定为记录器
我是一名优秀的程序员,十分优秀!