title: iOS Enable AVPlayer to continue playing in background
body: <p>I'm working on an app with a built in video player that plays <code>mp4</code> videos from disk and I'm trying to make it <strong>continue</strong> playing the audio (of the video) when <strong>app goes into background</strong>.</p>
  
  <p><em>I've read up on many other stack overflow questions but none of the answers worked for my case.</em></p>
  
  <p>I have added:</p>
  
  <pre><code>func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -&gt; Bool {
    do {
      try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
        print("AVAudioSession Category Playback OK")
  
      do {
        try AVAudioSession.sharedInstance().setActive(true)
        print("AVAudioSession is Active")
      } catch let error as NSError {
        print(error.localizedDescription)
      }
    } catch let error as NSError {
        print(error.localizedDescription)
    }
  }
  </code></pre>
  
  <p>Besides, I also have the required background mode key <code>App plays audio or streams audio/video using AirPlay</code> in the app's Info.plist file.
  However, the <code>AVPlayer</code> stops when the app goes into background.</p>
  
  <p>Anyone knows what might be wrong with the app?</p>
  
  <p>Thanks :)</p>
  
  <p><strong>Edit:</strong> Note: I'm using <code>AVPlayerLayer</code> together with <code>AVPlayer</code>. Maybe this is the problem?</p>