AVAudioPlayer和AVAudioRecorder:未调用委托方法 [英] AVAudioPlayer and AVAudioRecorder: Delegate Methods not Called

查看:288
本文介绍了AVAudioPlayer和AVAudioRecorder:未调用委托方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的委托方法 audioRecorderDidFinishRecording audioPlayerDidFinishPlaying 未被调用。这些方法应该触发'stopanimation`方法,在录制完成后停止动画。

My delegate methods audioRecorderDidFinishRecording and audioPlayerDidFinishPlaying are not being called. Those methods should trigger a 'stopanimation` method that stops an animation after recording is finished.

我已经在 audioPlayerDidFinishPlaying的结尾处拨打了 stopanimation / code>。

I have placed a call call to the stopanimation method at the end of audioPlayerDidFinishPlaying.

以下是代理人分配的相关代码:

Here is the relevant code where the delegate is assigned:

   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];
}


推荐答案

您的代码设置代理外观精细。

Your code setting the delegate looks fine.

您是否假设委托方法不被调用,因为动画不会停止或您是否尝试直接记录/断开方法?如果您没有直接进行测试,那么在假设它们不是这样做之前。

Are you assuming that the delegate methods are not called only because the animation does not stop or have you tried to log/breakpoint the methods directly? If you haven't tested directly do so before working on the assumption that they aren't.

如果您确认没有被调用,很可能您的动画正在绑定 self 对象使其无法响应AV代理方法。

If you have confirmed they are not being called the, most likely, your animation is tying up the self object such that it cannot respond to the AV delegate methods.

注释掉动画,只需放入AV代理方法的日志,看看它们是否被调用。

Comment out the animation and just put a log in the AV delegate methods to see if they are called.

这篇关于AVAudioPlayer和AVAudioRecorder:未调用委托方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆