聲音結束後,另一個聲音可以播放......但在這段代碼中,聲音正在混合......我該如何解決它? audioplayerdidfinishplaying問題! iphone sdk
-(IBAction) ... {
for (...) {
if (compare(Output, N1)) {
songPath = [[NSBundle mainBundle] pathForResource:@"a" ofType:@"wav"];
}
if (compare(Output, N2)) {
songPath = [[NSBundle mainBundle] pathForResource:@"b" ofType:@"wav"];
}
audioPlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: songPath] error:NULL];
[audioPlayer setDelegate:self];
[audioPlayer play];
}
}
-(void) audioPlayerDidFinishPlaying: (AVAudioPlayer *) player successfully: (BOOL) flag {
NSLog(@"Song FINISHED!!!!!!");
[player release];
}
您已將'[audioPlayer play]'放在'for'循環中。顯然,如果循環迭代次數超過1次,則會有多個音頻播放器一起播放。 – 2011-05-09 00:00:05