//
//  MainMenu.swift
//  sleazyburger
//
//  Created by Aslak Gronflaten on 1/24/15.
//  Copyright (c) 2015 Javelin. All rights reserved.
//

import UIKit
import AVFoundation

var musicPlayer : AVAudioPlayer?

class MainMenu : UIViewController {

    override func awakeFromNib() {
        loadMusic()
    }
    
    
    func loadMusic() {
        if musicPlayer == nil {
            let trackUrl = NSBundle.mainBundle().URLForResource("theme", withExtension: "aif")
            let player = AVAudioPlayer(contentsOfURL: trackUrl, error: nil)
            player.numberOfLoops = -1
            musicPlayer = player
        }
    }
    
    func playMusic() {
        if let m = musicPlayer {
            if !m.playing {
                m.play()
            }
        }
    }
    
    func stopMusic() {
        musicPlayer?.stop()
    }
    
    override func viewDidAppear(animated: Bool) {
        playMusic()
    }
}
