1.封装的方法,项目中如果多处使用,可以放在工具类中
static func play(name:String,type:String) {
let audioPath = Bundle.main.path(forResource: name, ofType: type)
if let filePath = audioPath {
let url = URL(fileURLWithPath: filePath)
var soundId:SystemSoundID = 0
AudioServicesCreateSystemSoundID(url as CFURL, &soundId)
AudioServicesPlaySystemSound(soundId)
}
}
2.使用方法
UtilsTool.play(name: "welcome_start",type: "caf")
记得点赞关注呀