1.導(dǎo)入AVFoundation框架
import AVFoundation
2.獲取音效對應(yīng)的soundID
guard let url = NSBundle.mainBundle().URLForResource("123.wav", withExtension: nil) else{return}
let urlCF = url as CFURLRef
var soundID:SystemSoundID = 0;
AudioServicesCreateSystemSoundID(urlCF, &soundID)
3.根據(jù)soundID播放音效,帶完成時(shí)回調(diào)
AudioServicesPlaySystemSoundWithCompletion(soundID) {
print("播放完成時(shí)回調(diào)")
//根據(jù)soundID釋放音效
AudioServicesDisposeSystemSoundID(soundID)
}