iOS 9 Split Screen Multitasking: Picture in Picture (PiP) Quick Start (Chinese Version)

iOS 9 Split Screen Multitasking: Picture in Picture (PiP) Quick Start (Chinese Version)

Follow the instructions in this section to use Picture-in-Picture (PiP) on a supported iPad.

To enable the video playback to support the picture-in-picture mode, make sure your Xcode project and App are configured as follows:

  • Set the Base SDK to "Latest iOS". See Setting the Base SDK in App Distribution Guide.
  • Check the project's target in Capabilities and check Audio and AirPlay in Background Modes. (In future Xcode updates, this option will be named Audio, AirPlay, and Picture in Picture.)
  • Make sure your app's audio session uses the appropriate category, such as AVAudiOSessionCategoryPlayback.

Next, choose the appropriate AVKit, AV Foundation, or WebKit class for video playback. The choice depends on the characteristics of your application and the user experience you want to provide.

  • The AVKit framework provides the AVPlayerViewController class, which automatically displays a picture-in-picture button for the user.

If you support PiP with AVKit but want to opt out of a specific PiP video, set the player view controller’s allowsPictureInPicturePlayback property to NO.

  • AVKit also provides the AVPictureInPictureController class, which can be used with the AVPlayerLayer class of the AV Foundation framework. Use this approach if you want to provide your own view controller and custom user interface for video playback.
  • If you support the picture-in-picture approach but want to opt out of the picture-in-picture feature for a specific video, do not associate the video's AVPlayerLayer with an AVPictureInPictureController object. As long as you instantiate a picture-in-picture controller with the playback layer, the playback video layer will have the picture-in-picture feature; opting out does not perform the instantiation.

The WebKit framework provides the WKWebView class, which supports the PiP feature of iOS 9.

If you use WebKit to support PiP, but want to opt out of PiP for a specific video, set the allowsPictureInPictureMediaPlayback property of the associated web view instance to NO. (This property will be available in a future beta of iOS 9.)

If you have an older app that uses the deprecated MPMoviePlayerViewController or MPMoviePlayerController to play videos, you must adopt the advanced iOS video playback framework to support picture-in-picture.

Important: Apple wants the Picture-in-Picture feature to always be accessible to users, and only respond to explicit requests from users. In particular, apps that fail to respond immediately to user requests to invoke the Picture-in-Picture feature when backed up will be rejected by the App Store.

iOS 9 automatically switches a full-screen video to PiP playback when the user presses the Home button or triggers a notification that takes them to another app. The requirements for video playback to use this feature are as follows:

  • Enable the picture-in-picture feature in your app as described earlier in this chapter.
  • Play the video full screen using a view's view filling the window's bounds.

Tip: Users can disable automatic PiP initiation in Settings > General > Multitasking > Persistent Video Overlay. If you think you have everything set up correctly but find that your video doesn’t go into PiP when you press the Home button, check this setting.

When the video played by your app switches to picture-in-picture playback, the system manages the presentation of the video content while your app continues to run in the background. When your app runs in the background, make sure to discard unneeded resources such as view controllers, views, images, and data caches. In this case, you expect to perform appropriate and necessary operations such as video synthesis, audio processing, downloading the next content to play, etc., but you must be careful to consume as few resources as possible. If your app consumes too many resources in the background, the system will terminate it.

<<:  iOS 9 split-screen multitasking: Slide Over & Split View Quick Start (Chinese version)

>>:  【WOT2015】Highlights of the Mobile Internet Developer Conference

Recommend

Why is Xiaomi in such a hurry to launch Xiaomi TV 2?

According to the new product release rules of the ...

Frost Descent | Why does frost-bitten cabbage taste better?

=================================================...

How to improve users’ acceptance of advertising? Here are 7 techniques!

Those great advertisements often come from the bra...

100 Golden Problem-solving Models for High School Physics (154 Lessons)

100 Golden Problem-solving Models for High School...

Wandering around old Tokyo with Japanese literary giants

Introduction In this book, we invited Nagai Kafu,...

A must-read for APP operators, 108 examples of marketing tactics!

Introduction: In the recent Double Eleven e-comme...