Please explain me the code below. `@IBAction func notePressed(_ sender: UIButton) {
guard let url = Bundle.main.url(forResource: "note\(sender.tag)", withExtension: "wav") else {
print("url not found")
return
}
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
try AVAudioSession.sharedInstance().setActive(true)
player = try AVAudioPlayer(contentsOf: url)
//player = try AVAudioPlayer(contentsOf: url, fileTypeHint: AVFileType.wav.rawValue)
player?.play()
} catch let error {
print(error.localizedDescription)
}`
Here are some questions: 1. Should I really use init(contentOf:fileTypeHint:) method or I can use init(contentOf:) only? What is the difference? 2. AVAudioSession.. When I just comment 2 line of code starting with "try", my app still work fine. Why do I need AVAudioSession? Thanks to everyone who is willing to help.