Class

AVPlayerView

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

Declaration

class AVPlayerView : NSView

Overview

The player view supports a variety of different controls styles, ranging from no controls to controls matching the look of QuickTime Player. This makes it easy for you to tailor the presentation to best match your use of the player view. Regardless of the selected controls style, the player view always supports a standard set of keyboard shortcuts to control playback:

  • The spacebar plays and pauses playback.

  • The right and left arrow keys step frame-by-frame through the video.

  • JKL Navigation:

    • The J key rewinds. You can press it multiple times to cycle through rewind speeds.

    • The K key stops playback.

    • The L key fast-forwards. You can press it multiple times to cycle through fast-forward speeds.

In addition to providing the core playback interface for your media applications, AVPlayerView also makes it simple to add trimming capabilities to your player. Invoking the player view’s beginTrimming(completionHandler:) method presents a trimming interface like that of QuickTime Player making it simple to trim the media to the desired time range.

Topics

Accessing the Player Object

var player: AVPlayer?

The player instance that provides the media content for the view.

Customizing the User Interface

var controlsStyle: AVPlayerViewControlsStyle

The player view’s controls style.

enum AVPlayerViewControlsStyle

Constants that specify which controls the player view displays.

var showsFrameSteppingButtons: Bool

A Boolean value that determines whether the player view displays frame stepping buttons.

var showsSharingServiceButton: Bool

A Boolean value that determines whether the player view displays a sharing service button.

var showsFullScreenToggleButton: Bool

A Boolean value that determines whether the player view displays a full-screen toggle button.

var showsTimecodes: Bool

A Boolean value that determines whether the player view displays timecodes, if available.

var contentOverlayView: NSView?

A view that adds additional custom views between the video content and the controls.

var actionPopUpButtonMenu: NSMenu?

An action pop-up button menu displayed by the player view.

var updatesNowPlayingInfoCenter: Bool

A Boolean value that indicates whether the player view controller updates the Now Playing info center.

Customizing the Video Presentation

var isReadyForDisplay: Bool

A Boolean value that indicates whether the current player item’s first video frame is ready for display.

var videoBounds: NSRect

The current size and position of the video image as displayed within the player view’s bounds.

var videoGravity: AVLayerVideoGravity

A value that determines how the player view displays video content within its bounds.

Configuring Picture in Picture Playback

var allowsPictureInPicturePlayback: Bool

A Boolean value that determines whether the player view allows Picture in Picture playback.

protocol AVPlayerViewPictureInPictureDelegate

A protocol that defines the methods to implement to respond to Picture in Picture playback events.

Trimming Media

Implementing Trimming (macOS)

Implement a QuickTime media-trimming experience in your macOS app.

var canBeginTrimming: Bool

A Boolean value that indicates whether the player view can begin trimming.

func beginTrimming(completionHandler: ((AVPlayerViewTrimResult) -> Void)?)

Sets the player view’s controls panel into trimming mode.

enum AVPlayerViewTrimResult

Constants that specify what action the user took when trimming media in a player view.

Displaying the Chapter and Title

func flashChapterNumber(Int, chapterTitle: String?)

Momentarily displays the provided chapter number and title in the player view.

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.

Using AVKit in iOS

This sample code project demonstrates techniques for tracking AVPlayerViewController presentation state across multiple application scenarios, including being displayed fullscreen, embedded inline, or as Picture in Picture.

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.

Adding Information to the Info Panel (tvOS)

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

class AVPlayerViewController

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

class AVPictureInPictureController

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

class AVInterstitialTimeRange

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

class AVNavigationMarkersGroup

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