I just converted to Swift 3 and I need help with this error. I got this error when I converted to swift 3 yesterday and this full code was working great. I put a try? in it but the it did not fix the error at all it stayed the same.
import Foundation
import AVFoundation
class AudioHelper: NSObject, AVAudioPlayerDelegate {
var player : AVAudioPlayer?
class var defaultHelper : AudioHelper {
struct Static {
static let instance : AudioHelper = AudioHelper()
}
return Static.instance
}
override init() {
super.init()
}
func initializeAudio() {
let url = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("", ofType: "")!)
self.player = try! AVAudioPlayer(contentsOfURL: url, fileTypeHint: nil)
self.player?.numberOfLoops = -1
self.player?.play()
}
func stopAudio() {
self.player?.stop()
self.player?.prepareToPlay()
}
func startAudio() {
AVAudioSession.sharedInstance().setActive(true, error: nil)
self.player?.play()
}
func audioPlayerDidFinishPlaying(player: AVAudioPlayer, successfully flag: Bool) {
AVAudioSession.sharedInstance().setActive(false, error: nil)
}
}