IOS音效

step1:申明声音的id:

SystemSoundID sound;

step2:得到音频文件的路径

NSString *audioFile=[[NSBundle mainBundle] pathForResource:@"bell.wav" ofType:nil];

NSURL *fileUrl=[NSURL fileURLWithPath:audioFile];

step3:根据音频路径创建SystemSoundID

AudioServicesCreateSystemSoundID((__bridge CFURLRef)fileUrl, &sound);

step4:播放音效设置

1,AudioServicesPlaySystemSound(sound);

2,AudioServicesPlayAlertSound(sound);

 

***:如果需要在播放完之后执行某些操作,可以调用如下方法注册一个播放完成回调函数

AudioServicesAddSystemSoundCompletion(sound, NULL, NULL, soundCompleteCallback, NULL);

 

 

posted @ 2015-08-24 13:48  IT菜鸟来袭  阅读(118)  评论(0编辑  收藏  举报