Firstly import your sound files into your project.
then write following code into AppDelegate.swift. note to repeat your your music, add audioPlayer.numberOfLoops=-1;
import UIKit
import AVFoundation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var audioPlayer = AVAudioPlayer()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
var alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(“bgmusic”, ofType: “mp3”)!)
println(alertSound)
var error:NSError?
audioPlayer = AVAudioPlayer(contentsOfURL: alertSound, error: &error)
audioPlayer.prepareToPlay()
audioPlayer.play()
return true
}