in the gameScene.swift:
declaration:
var backgroundMusic: SKAudioNode!
in didMoveToView:
if let musicURL = NSBundle.mainBundle().URLForResource("Jalandhar", withExtension: "mp3") {
backgroundMusic = SKAudioNode(URL: musicURL)
addChild(backgroundMusic)
}
i ended up using AVAudioPlayer to workaround it , code may be useful:
declare as property :
var audioPlayer: AVAudioPlayer!
then in a function :
let filePath = NSBundle.mainBundle().pathForResource("musicfile", ofType: "mp3")
let url = NSURL.fileURLWithPath(filePath!)
do {
audioPlayer = try AVAudioPlayer(contentsOfURL: url, fileTypeHint: nil)
audioPlayer.play() }
catch {
print("music error")
}