【问题标题】:ios AVAudioPlayer plays sound with echoios AVAudioPlayer 播放带有回声的声音
【发布时间】:2012-09-28 21:23:53
【问题描述】:

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

}

【问题讨论】:

    标签: iphone ios ipad avaudioplayer


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-22
      • 1970-01-01
      • 1970-01-01
      • 2014-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多