1

我有两个 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];
    }

}
4

1 回答 1

0

我发现错误我正在使用“forControlEvents:UIControlEventAllTouchEvents”设置 UIButton,并且 actionw 被多次触发。我用这个 forControlEvents:UIControlEventTouchDown 替换 UIButton 并且工作得很好。

于 2012-09-29T00:59:54.827 回答