ios AVAudioPlayer播放带有回声的声音

时间:2012-09-28 21:23:54

标签: iphone ios ipad avaudioplayer

我有两个AVAudioPlayer来确定在那之后做了什么声音。第一个声音播放得很好,但第二个声音(twoPlayer)播放带有回声的声音。你们谁知道为什么或如何发生这种情况?

我的.h文件中有这个:

@interface myClass : UIViewController<AVAudioPlayerDelegate>
{
    AVAudioPlayer *onePlayer;
    AVAudioPlayer *twoPlayer;
}
@property (retain, nonatomic) AVAudioPlayer *onePlayer;
@property (retain, nonatomic) AVAudioPlayer *twoPlayer;


.m file:

    NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"m4a"];

    NSURL *url = [NSURL fileURLWithPath:urlAddress];

    NSError *error;
    twoPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
    twoPlayer.delegate=self;
    twoPlayer.volume=0.5;
    if (twoPlayer == nil)
        NSLog(@"[error description]");
    else
        [twoPlayer play];

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {


    if (player==onePlayer) {
        [onePlayer release];
    }
    if (player==twoPlayer) {
        [numberPlayer release];
    }

}

1 个答案:

答案 0 :(得分:0)

我发现错误我正在使用“forControlEvents:UIControlEventAllTouchEvents”设置UIButton,并且actionw被触发了一次以上。我用这个forControlEvents替换了UIButton:UIControlEventTouchDown并且运行正常。