Sample Code

Adopting Custom Interactive Overlays, Channel Flipping, and Parental Controls in tvOS Video Playback

This sample demonstrates support for custom interactive overlays, and parental controls, using AVPlayerViewController.

Download

Overview

VideoPlaybackViewController hosts instances of AVPlayerViewController. This class has all of the new API calls.

CustomInteractiveVideoOverlay.xib and CustomInteractiveOverlayViewController.swift describe the custom overlay and its behavior. In this example, the overlay is purely for show: It displays several “up next” items, but does not perform any action if they are selected.

Configure the Sample Code Project

To test channel flipping, you will need to replace the assets in the sample with live streams, as channel-flipping is only supported for navigation from a live stream.

By default, this sample demonstrates automatic support for parental restrictions. To demonstrate, you will need to activate parental restrictions: • Navigate to Settings > General > Restrictions • Turns on “Restrictions” and set a passcode (for demonstration purposes, “1111” is fine; do not lose this passcode!) • Scroll down to the “Allowed Content” section, select “Movies” and/or “TV Shows,” and set a restriction level, e.g. “PG” or “PG-13” if you are in the United States. The first demo video has a rating of “PG” and the second has a rating of “PG-13”; you can find/edit these ratings in MainViewController.swift. This sample also demonstrates explicit support for parental restrictions, by directly calling playerItem.requestPlaybackRestrictionsAuthorization(_ completion). You can test this by changing the value of checkParentalControlsExplicitly to true.

See Also

Media Playback

Adopting Picture in Picture in a Standard Player

Add Picture in Picture (PiP) playback to your app using a player view controller.

Adopting Picture in Picture in a Custom Player

Add controls to your custom player user interface to invoke Picture in Picture (PiP) playback.

Working with Interstitial Content in tvOS

Present additional content such as legal text, content warnings, or advertisements alongside your main media presentation.

Adding Information to the Info Panel (tvOS)

Add metadata information and navigation markers to the Info panel in Apple TV.

AVPlayerViewController

A view controller that displays the video content from a player object along with system-supplied playback controls.

AVPlayerView

A macOS-only object that displays the video content from a player object along with system-supplied playback controls.

AVPictureInPictureController

A controller that responds to user-initiated Picture in Picture playback of video in a floating, resizable window.

AVInterstitialTimeRange

A time range in an audiovisual presentation designated as interstitial content, such as advertisements or legal notices.

AVNavigationMarkersGroup

A set of markers for navigating playback of an audiovisual presentation.