I'm trying to play a sound after the NSTimer has counted down, so far I know the selector is being called but for some reason no sound is playing.
let timer = NSTimer(fireDate: task.date, interval: 0, target: self, selector: Selector("update"), userInfo: nil, repeats: false)
NSRunLoop.mainRunLoop().addTimer(timer, forMode: NSRunLoopCommonModes)
func update() {
backgroundMusic = self.setupAudioPlayerWithFile("music", type:"mp3")
backgroundMusic.volume = 1 backgroundMusic.prepareToPlay() backgroundMusic.play() println("we made it!")
}
func setupAudioPlayerWithFile(file:NSString, type:NSString) -> AVAudioPlayer {
/ var path = NSBundle.mainBundle().pathForResource(file as String, ofType: type as String)
var url = NSURL.fileURLWithPath(path!)
var error: NSError?
var audioPlayer:AVAudioPlayer?
audioPlayer = AVAudioPlayer(contentsOfURL: url, error: &error)
return audioPlayer! }
The timer works perfectly, it executes the function update and I know that because I always see the println in the console, but the sound never plays. Anyone know a solution? Or another method of getting the sound to play, i need the sound to play right after the timer finishes