Created
July 18, 2019 11:51
-
-
Save JosephTLyons/d7af87de3c1d51b5c9d50baf8d94ec6d to your computer and use it in GitHub Desktop.
Angela Yu Lesson 87: Create a Method to Contain the Sound Playing Functionality (Solution)
This file contains hidden or 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
@IBAction func notePressed(_ sender: UIButton) { | |
playSound("note" + String(sender.tag)) | |
} | |
func playSound(_ fileName: String) { | |
let soundURL = Bundle.main.url(forResource: fileName, withExtension: "wav") | |
do { | |
try audioPlayer = AVAudioPlayer(contentsOf: soundURL!) | |
} | |
catch { | |
} | |
audioPlayer.play() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment