Answers for "play music in swift swiftui"

1

swiftui play mp3

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 :(
}
Posted by: Guest on December-20-2020

Code answers related to "Swift"

Browse Popular Code Answers by Language