In my app, for a button click or any tap I need to play one beep sound on user click or tap. I added this code in AppDelegate:
var audioPlayer: AVAudioPlayer?
func playSound() {
let audioFileURL = Bundle.main.url(forResource: "/Sound/music1", withExtension: "mp3")
do {
try audioPlayer = AVAudioPlayer(contentsOf: audioFileURL!)
} catch let error {
print(error.localizedDescription)
}
audioPlayer?.play()
}
I don't know how to merge or pass these methods to all of my taps and button clicks to play that beep sound. I don't want to add in each button click in each vc. Any help with dynamic solutions for the button click and any touch event in my app?