Play sound in SWIFT 5
yipcodes
Posted on June 15, 2022
import AVKit
class ViewController: UIViewController {
var player: AVAudioPlayer?
@IBAction func buttonPressed(_ sender: UIButton) {
playSound(soundTitle:sender.currentTitle!)
}
func playSound(soundTitle:String) {
let path = Bundle.main.path(forResource: "soundName",ofType:"mp3")
let url = URL(fileURLWithPath: path!)
do {
player = try AVAudioPlayer(contentsOf: url)
player?.play()
} catch let error {
print(error.localizedDescription)
}
}
}
💖 💪 🙅 🚩
yipcodes
Posted on June 15, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
githubcopilot AI Innovations at Microsoft Ignite 2024 What You Need to Know (Part 2)
November 29, 2024