Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import AVFoundation
- class ViewController: UIViewController, AVAudioPlayerDelegate {
- var audioPlayer: AVAudioPlayer!
- override func viewDidLoad() {
- super.viewDidLoad()
- }
- @IBAction func notePressed(_ sender: UIButton) {
- // Directory path of sound file
- let soundURL = Bundle.main.url(forResource: "note1", withExtension: "wav")
- do {
- audioPlayer = try AVAudioPlayer(contentsOf: soundURL!)
- }
- catch {
- print(error)
- }
- audioPlayer.play()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment