static void SoundFinished(SystemSoundID soundID,void* sample){
/*播放全部结束,因此释放所有资源 */
AudioServicesDisposeSystemSoundID(soundID);
CFRelease(sample);
CFRunLoopStop(CFRunLoopGetCurrent());
}
+(void)Sound
{
SystemSoundID soundID;
NSString * filePath=[[NSBundle mainBundle] pathForResource:@"test" ofType:@"wav"];
NSURL* sample = [NSURL fileURLWithPath:filePath];
CFURLRef urlRef=(__bridge_retained CFURLRef)sample;
OSStatus err = AudioServicesCreateSystemSoundID(urlRef, &soundID);
if (err) {
NSLog(@"Error occurred assigning system sound!");
}
/*添加音频结束时的回调*/
AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, SoundFinished,urlRef);
/*开始播放*/
AudioServicesPlaySystemSound(soundID);
CFRunLoopRun();
}