Guest User

Untitled

a guest
May 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. import UIKit
  2. import AVFoundation
  3.  
  4. class ViewController: UIViewController, AVAudioPlayerDelegate{
  5.  
  6. var audioPlayer: AVAudioPlayer!
  7.  
  8. @IBAction func notePressed(_ sender: UIButton) {
  9. playSound("note\(sender.tag)")
  10. }
  11.  
  12. func playSound(_ soundFile: String) {
  13. let soundURL = Bundle.main.url(forResource: soundFile, withExtension: "wav")
  14. do{
  15. audioPlayer = try AVAudioPlayer(contentsOf: soundURL!)
  16. }
  17. catch {
  18. print(error.localizedDescription)
  19. }
  20. audioPlayer.play()
  21. }
  22. }
Add Comment
Please, Sign In to add comment