NSString *sndPath = [[NSBundle mainBundle] pathForResource:@"click" ofType:@"aiff"]; SystemSoundID soundID; AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:sndPath], &soundID); AudioServicesPlaySystemSound(soundID); AudioServicesDisposeSystemSoundID(soundID);
我已经检查了我的系统首选项,是的,我确实有“播放用户界面音效”勾选。。。我可能做错了什么?
在声音播放完之前不要处理它。你可以这样做:
AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, (AudioServicesSystemSoundCompletionProc)AudioServicesDisposeSystemSoundID, NULL);