2012-09-28 64 views
1

我有两个AVAudioPlayer来确定什么声音已经完成后做些什么。第一个声音播放得很好,但第二个声音(twoPlayer)播放带有回声的声音。你们中的任何人都知道为什么或如何发生这种情况?ios AVAudioPlayer播放声音与回声

我有这个在我的.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]; 
    } 

} 

回答

0

我发现我设置一个UIButton错误与“forControlEvents:UIControlEventAllTouchEvents”和actionw被触发了更多然后一次。我用这个forControlEvents替换UIButton:UIControlEventTouchDown并且工作得很好。