Created
September 30, 2017 15:50
-
-
Save iannase/546e31aa45862cfdc502ee9eb531bb30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import AVFoundation | |
class ViewController: UIViewController, AVAudioPlayerDelegate { | |
var audioPlayer: AVAudioPlayer! | |
let soundArray = ["note1.wav", "note2.wav", "note3.wav", "note4.wav", "note5.wav", "note6.wav", "note7.wav"] | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
@IBAction func notePressed(_ sender: UIButton) { | |
playSound(soundFileName: soundArray[sender.tag - 1]) | |
} | |
func playSound(soundFileName : String) { | |
let soundUrl = Bundle.main.url(forAuxiliaryExecutable: soundFileName) | |
do { | |
audioPlayer = try AVAudioPlayer(contentsOf: soundUrl!) | |
} catch { | |
print(error) | |
} | |
audioPlayer.play() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment