title: Xcode swift - Background mode - Audio in AVPlayer when locked
body: <p>I have got an AVPlayer setup but I cant seem to get the video audio to continue to play when the phone is locked or on the home screen. I have edited the info.plist and enabled the audio background mode but I think need to add some code. Please could you help me out. Thanks</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import UIKit
  import AVFoundation
  import AVKit
  
  class ViewController: UIViewController {
  
      @IBAction func WarmUp(sender: UIButton)
      {
          WarmUpVideo()
      }
  
      func WarmUpVideo()
      {
          let filePath = NSBundle.mainBundle().pathForResource("132", ofType: "MOV")
          let videoURL = NSURL(fileURLWithPath: filePath!)
  
          let player = AVPlayer(URL: videoURL)
          let playerViewController = AVPlayerViewController()
  
          playerViewController.player = player
  
          self.presentViewController(playerViewController, animated: true) { () -&gt; Void in playerViewController.player!.play()
          }
  
      }
  
      func playExternalVideo()
      {
  
  }
  
  
      @IBAction func CoolDown(sender: UIButton)
      {
          CoolDownVideo()
      }
  
      func CoolDownVideo()
      {
          let filePath = NSBundle.mainBundle().pathForResource("132", ofType: "mp4")
          let videoURL = NSURL(fileURLWithPath: filePath!)
  
          let player = AVPlayer(URL: videoURL)
          let playerViewController = AVPlayerViewController()
  
          playerViewController.player = player
  
          self.presentViewController(playerViewController, animated: true) { () -&gt; Void in playerViewController.player!.play()
          }
  
      }
  
  }
  </code></pre>