---
title: "#25: Picture in Picture 📺"
url: https://littlebitesofcocoa.com/25-picture-in-picture
author: Jake Marsh
published: 2015-06-26
topics: ["iOS 9","Media"]
description: "One of the coolest new features in iOS 9 is the new Picture in Picture functionality on iPad. This lets users watch video content from an app even while..."
---

# #25: Picture in Picture 📺

By Jake Marsh, June 26, 2015. HTML: https://littlebitesofcocoa.com/25-picture-in-picture

One of the coolest new features in **iOS 9** is the new **Picture in Picture** functionality on **iPad**. This lets users watch video content from an app even while it's in the background.

To support it in our app, we'll first make sure you set the `Playback` audio category in our `application(application:didFinishLaunchingWithOptions:)` function:

``` swift
do {
  try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
} catch { }
```

Then we'll use `AVPlayerViewController` to play video content. **Picture in Picture** mode will automatically kick-in if our app enters background but only if: 1.) our player is full screen, 2.) video content is playing in it, <i>and</i> 3.) **Picture in Picture** is supported on the device.

Next we'll implement this wonderfully long delegate method to restore our player UI when the user returns from **Picture in Picture** mode:

``` swift
func playerViewController(playerViewController: AVPlayerViewController, restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: (Bool) -> Void) {
  navigationController?.presentViewController(playerViewController, animated: true) {
    completionHandler(true)
  }
}
```

## More About PIP

- If we need to support a generic `AVPlayerLayer`, **AVKit** also includes a new `AVPictureInPictureController`.

- We also get **PIP** for free in `WKWebView` assuming our app has the `Playback` audio session category set.
