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