GregLeck

Untitled

May 17th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.60 KB | None | 0 0
  1. import UIKit
  2. import AVFoundation
  3.  
  4. class ViewController: UIViewController, AVAudioPlayerDelegate {
  5.    
  6.     var audioPlayer: AVAudioPlayer!
  7.    
  8.     override func viewDidLoad() {
  9.         super.viewDidLoad()
  10.     }
  11.  
  12.     @IBAction func notePressed(_ sender: UIButton) {
  13.        
  14.         // Directory path of sound file
  15.         let soundURL = Bundle.main.url(forResource: "note1", withExtension: "wav")
  16.        
  17.         do {
  18.             audioPlayer = try AVAudioPlayer(contentsOf: soundURL!)
  19.         }
  20.         catch {
  21.             print(error)
  22.         }
  23.        
  24.         audioPlayer.play()
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment