title: Swift: Keep playing sounds when the device is locked
body: <p>I'm using the following code to play a sound off a URL from the internet:</p>
  
  <pre><code>var audioPlayer = AVPlayer()
  </code></pre>
  
  <p>...</p>
  
  <pre><code>let audioSession = AVAudioSession.sharedInstance()
  audioSession.setCategory(AVAudioSessionCategoryAmbient, error: nil)
  
  let url = trackFileName
  let playerItem = AVPlayerItem( URL:NSURL( string:url ) )
  audioPlayer = AVPlayer(playerItem:playerItem)
  audioPlayer.rate = 1.0;
  player.play()
  </code></pre>
  
  <p>I'm trying to make sure it keeps playing in the background which is the reason why I'm using "AVAudioSession.sharedInstance()". When I try it out in the simulator by locking the screen, it keeps playing like it's supposed to. But if I play it in a device, the sounds shuts off as soon as the screen looks itself automatically or I lock it myself. </p>
  
  <p>What am I missing in my code?</p>