I've found a bug on my app but only when the app runs on a device, if the app runs using the simulator no error is generated.
I've located the error down to the background music script, the output error is fatal error: unexpectedly found nil while unwrapping an Optional value
. I've looked at similar questions here but found no remedy.
Can anyone help fix my code?
var bgMusicURL:NSURL = NSBundle.mainBundle().URLForResource("bgMusic", withExtension: "aif")!
backgroundMusicPlayer = AVAudioPlayer(contentsOfURL: bgMusicURL, error: nil) //error here!!!
backgroundMusicPlayer.numberOfLoops = -1
backgroundMusicPlayer.prepareToPlay()
backgroundMusicPlayer.play()
Please let me know if you need more code.
Thank you.