let engine = AVAudioEngine() let playerNode = AVAudioPlayerNode() engine.attach(playerNode) engine.connect(playerNode, to: engine.mainMixerNode, format: nil)
guard let audioFile = try? AVAudioFile(forReading: Bundle.main.url(forResource: "example", withExtension: "mp3")!) else { return }
playerNode.scheduleFile(audioFile, at: nil)
DispatchQueue.main.async { try? engine.start() }