Iphone AVAudioPlayer和AVAudioRecorder:未调用委托方法
我的委托方法未被调用。这些方法应触发“stopanimation”方法,该方法在录制完成后停止动画 我已经在Iphone AVAudioPlayer和AVAudioRecorder:未调用委托方法,iphone,ios4,delegates,avaudioplayer,avaudiorecorder,Iphone,Ios4,Delegates,Avaudioplayer,Avaudiorecorder,我的委托方法未被调用。这些方法应触发“stopanimation”方法,该方法在录制完成后停止动画 我已经在AudioPlayerDifinishPlay的末尾调用了stopanimation方法 以下是分配给代表的相关代码: VoiceEditor.h @interface VoiceEditor : UIViewController <UITextFieldDelegate, AVAudioRecorderDelegate, AVAudioPlayerDelegate&
AudioPlayerDifinishPlay
的末尾调用了stopanimation
方法
以下是分配给代表的相关代码:
VoiceEditor.h
@interface VoiceEditor : UIViewController <UITextFieldDelegate, AVAudioRecorderDelegate, AVAudioPlayerDelegate>{
}
VoiceEditor.m
- (void)record{
recorder = [[AVAudioRecorder alloc] initWithURL:[NSURL fileURLWithPath:pathString] settings:recordSettings error:nil];
[recorder setDelegate:self];
[recorder record];
recording = YES;
[pauseButton setImage:[UIImage imageNamed:@"stop.png"] forState:UIControlStateNormal];
[pauseButton setEnabled:YES];
[playButton setEnabled:NO];
[recordButton setEnabled:NO];
[self beginAnimation];
}
- (void)play{
player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:pathString] error:nil];
double seconds=[player duration];
NSLog(@"%f",seconds);
[player setDelegate:self];
[player play];
playing = YES;
[recordButton setEnabled:NO];
[pauseButton setEnabled:YES];
[playButton setEnabled:NO];
[self beginAnimation];
}
VoiceEditor.h
@接口VoiceEditor:UIViewController{
}
VoiceEditor.m
-(作废)记录{
recorder=[[AVAudioRecorder alloc]initWithURL:[NSURL fileURLWithPath:pathString]设置:recordSettings错误:nil];
[记录器设置代表:自我];
[录音记录];
记录=是;
[pauseButton setImage:[UIImage ImageName:@“stop.png”]用于状态:UIControlStateNormal];
[暂停按钮设置启用:是];
[播放按钮设置已启用:否];
[记录按钮设置启用:否];
[自我再生];
}
-(无效)播放{
player=[[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:pathString]错误:nil];
双秒=[玩家持续时间];
NSLog(@“%f”,秒);
[玩家设置代表:自我];
[玩家游戏];
玩=是;
[记录按钮设置启用:否];
[暂停按钮设置启用:是];
[播放按钮设置已启用:否];
[自我再生];
}
尝试传递错误参数,以确保正确创建记录器对象
NSError *err=nil;
recorder = [[AVAudioRecorder alloc] initWithURL:[NSURL fileURLWithPath:pathString] settings:recordSettings error:&err];
if(!recorder){
NSLog(@"recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
}
您设置委托的代码看起来很好 您是否假定仅因为动画未停止而调用委托方法,或者您是否尝试直接记录/中断这些方法?如果你没有直接测试过,那么在假设他们没有测试之前就这样做 如果您已确认它们没有被调用,则很可能是您的动画正在绑定
self
对象,使其无法响应AV委托方法
注释掉动画,在AV委托方法中放一个日志,看看它们是否被调用 检查当前AVAudioSession类别。如果类别未设置为AVAudioSessionRecord或AVAudioSessionPlayAndRecord,则记录器将无法工作,并且不会调用其任何委托方法。AVAudioSession类别可以使用setCategory:error:方法更改。例如:
NSError *sessionCategoryError = nil;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
BOOL success = [audioSession setCategory: AVAudioSessionCategoryPlayAndRecord
error: &sessionCategoryError];
我已经检查了断点,它并没有停止。但当我在设备上运行它时,它工作了。我的意思是委托方法被调用