If a button is tapped, I'd like it to play sound.
In "playSound" function below I'd like to instantiate AVAudioPlayer and play the sound but Xcode outputted Exception caught in AudioQueueInternalNotifyRunning - error -66671 error and cannot play the sound.
A hoge.mp3 is already imported.
If I instantiate AVAudioPlayer out of the function, it successes but I would like to instantiate it in the function.
Do you have any solution?
Thank you.
func playSound(title:String){
let tmpSound = try! AVAudioPlayer(data:NSDataAsset(name:title)!.data)
tmpSound.play()
}
Button(action: {
playSound(soundName: "hoge")
}){
Text("Play".font(.title)
}