IOS音效

step1:申明聲音的id:函數

SystemSoundID sound;spa

step2:獲得音頻文件的路徑回調函數

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

NSURL *fileUrl=[NSURL fileURLWithPath:audioFile];io

step3:根據音頻路徑建立SystemSoundIDclass

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

step4:播放音效設置file

1,AudioServicesPlaySystemSound(sound);方法

2,AudioServicesPlayAlertSound(sound);di

 

***:若是須要在播放完以後執行某些操做,能夠調用以下方法註冊一個播放完成回調函數

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

相關文章
相關標籤/搜索