Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import AVFoundation
- class ViewController: UIViewController, AVAudioPlayerDelegate{
- var audioPlayer: AVAudioPlayer!
- @IBAction func notePressed(_ sender: UIButton) {
- playSound("note\(sender.tag)")
- }
- func playSound(_ soundFile: String) {
- let soundURL = Bundle.main.url(forResource: soundFile, withExtension: "wav")
- do{
- audioPlayer = try AVAudioPlayer(contentsOf: soundURL!)
- }
- catch {
- print(error.localizedDescription)
- }
- audioPlayer.play()
- }
- }
Add Comment
Please, Sign In to add comment