📜  swiftui 播放 mp3 - Swift 代码示例

📅  最后修改于: 2022-03-11 15:00:59.299000             🧑  作者: Mango

代码示例1
import AVFoundation

var bombSoundEffect: AVAudioPlayer?
let path = Bundle.main.path(forResource: "example.mp3", ofType:nil)!
let url = URL(fileURLWithPath: path)

do {
    bombSoundEffect = try AVAudioPlayer(contentsOf: url)
    bombSoundEffect?.play()
} catch {
    // couldn't load file :(
}