Question : swiftui play mp3
Answered by : adorable-angelfish-q9qh9mcdbb7x
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 :(
}
Source : | Last Update : Sun, 27 Dec 20