AVFoundationをインポート
import AVFoundation
var sound: AVAudioPlayer? func playSound() { if let path = Bundle.main.path(forResource: "2_cymbal", ofType: "mp3") { do { sound = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: path)) print("Playing sound") sound?.play() } catch { print( "Could not find file") } } }
参考: