1.导入依赖包
import AVFoundation
2.创建 AVAudioPlayer 对象
var player: AVAudioPlayer!
3.通过 Bundle 获取本地音频的 url
let url = Bundle.main.url(forResource:"test", withExtension: "wav")!
4.初始化播放器
do{
player = try AVAudioPlayer(contentsOf: url)
}catch{
print(error)
}
5.进行播放
player.play()
6.播放器暂停和停止
player.pause()
player.stop()