Вот как вы можете использовать NSTimer для обратного вызова soundDidFinishPlaying даже в тихом режиме.
- (IBAction)playSelectedSound:(id)sender {
if (!self.isPlaying)
{
// playing the sound
NSString *fileName = [soundsFileNames objectAtIndex:self.selectedIndex];
SystemSoundID topClick;
NSBundle *bundle = [NSBundle mainBundle];
NSString *topClikFile = [bundle pathForResource:fileName ofType:@"aiff"];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL URLWithString:topClikFile], &topClick);
AudioServicesPlaySystemSound(topClick);
// getting the file duration
AudioFileID audioFileID;
AudioFileOpenURL((__bridge CFURLRef)[NSURL URLWithString:topClikFile], kAudioFileReadPermission, 0, &audioFileID);
NSTimeInterval seconds;
UInt32 propertySize = sizeof(seconds);
OSStatus st = AudioFileGetProperty(audioFileID, kAudioFilePropertyEstimatedDuration, &propertySize, &seconds);
// fire the timer
if (st == 0)
{
[NSTimer scheduledTimerWithTimeInterval:seconds target:self selector:@selector(soundDidFinishPlaying) userInfo:nil repeats:NO];
}
self.isPlaying = YES;
}
}
- (void)soundDidFinishPlaying {
self.isPlaying = NO;
}