点击按钮会有音效、进入某个vc会播放背景音乐等,都是加载本地沙盒的音效
0.本地沙盒中添加音效:
本地沙盒的音效文件
1.加载音效的方法
//加载本地沙盒音效
func loadSound(_ soundFileName: String) -> SystemSoundID {
let path = Bundle.main.path(forResource: soundFileName, ofType: nil)
let url = URL(fileURLWithPath: path!)
var soundId: SystemSoundID = 0
AudioServicesCreateSystemSoundID(url as CFURL, &soundId)
return soundId
}
2.音效的使用:
//定义音效属性
var btnClickSoundId: SystemSoundID = 0
//给音效赋值
btnClickSoundId = loadSound("ding3.mp3")
//调起音效
AudioServicesPlaySystemSound(self.btnClickSoundId)
网友评论