我希望我的声音文件随后播放三遍。但是,它只播放一次。我猜当[crashSound play]
第二次调用时,声音还没有完成播放,所以任何后续调用都会丢失。我该如何解决。即,我怎样才能使相同的文件在完成当前播放后再次播放?
@interface Game()
{
// code...
AVAudioPlayer *crashSound;
// code...
}
@end
@implementation Game
- (id) init
{
// code...
NSBundle *bundle = [NSBundle mainBundle];
NSURL *crashSoundFile = [bundle URLForResource: @"crashSound" withExtension: @"wav"];
crashSound = [[AVAudioPlayer alloc] initWithContentsOfURL:crashSoundFile error:NULL];
// code...
}
-(void) play // this is my "main" method that will be called once the playButton is pressed
{
[crashSound play];[crashSound play];[crashSound play];
}
@end