AVPlayerLayer Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AVFoundation.framework
Availability
Available in iOS 4.0 and later.
Companion guide
Declared in
AVPlayerLayer.h
Related sample code

Overview

AVPlayerLayer is a subclass of CALayer to which an AVPlayer object can direct its visual output.

You can create a layer as illustrated in the following code fragment:

AVPlayer *player = <#A configured AVPlayer object#>;
 
CALayer *superlayer = <#Get a CALayer#>;
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
[superlayer addSublayer:playerLayer];

The videoGravity property defines how the video content is displayed within the player layer’s bounds rect.

The value for the contents key of a player layer is opaque and effectively read-only.

During playback, AVPlayer may compensate for temporal drift between its visual output and its audible output to one or more independently-clocked audio output devices by adjusting the timing of its associated player layers. The effects of these adjustments are usually very small; however, clients that wish to remain entirely unaffected by such adjustments may wish to place other layers for which timing is important into independently timed subtrees of their layer trees.

You can create arbitrary numbers of player layers with the same AVPlayer object. Only the most recently created player layer will actually display the video content on-screen.

Tasks

Creating a Player Layer

Getting and Setting Player Layer Values

Properties

player

The player for which the player layer displays visual output.

@property(nonatomic, retain) AVPlayer *player
Availability
  • Available in iOS 4.0 and later.
Declared In
AVPlayerLayer.h

readyForDisplay

A Boolean value that indicates whether the first video frame has been made ready for display for the current item of the associated player. (read-only)

@property(nonatomic, readonly, getter=isReadyForDisplay) BOOL readyForDisplay
Discussion

Use this property as an indicator of when best to show or animate-in a player layer into view. A player layer may be displayed, or made visible, while this property is NO, however the layer will not have any user-visible content until the value becomes YES.

This property remains NO for a player’s currentItem whose asset contains no enabled video tracks.

Availability
  • Available in iOS 4.0 and later.
Declared In
AVPlayerLayer.h

videoGravity

Specifies how the video is displayed within a player layer’s bounds.

@property(copy) NSString *videoGravity
Discussion

Options are AVLayerVideoGravityResizeAspect, AVLayerVideoGravityResizeAspectFill, and AVLayerVideoGravityResize. The default is player.

This property is animatable.

Availability
  • Available in iOS 4.0 and later.
See Also
Declared In
AVPlayerLayer.h

videoRect

The current size and position of the video image as displayed within the receiver's bounds. (read-only)

@property(nonatomic, readonly) CGRect videoRect
Availability
  • Available in iOS 7.0 and later.
Declared In
AVPlayerLayer.h

Class Methods

playerLayerWithPlayer:

Returns a player layer to display the visual output of a specified player.

+ (AVPlayerLayer *)playerLayerWithPlayer:(AVPlayer *)player
Parameters
player

The player for which the player layer displays visual output.

Return Value

A player layer configured to display the visual output of player.

Availability
  • Available in iOS 4.0 and later.
Related Sample Code
Declared In
AVPlayerLayer.h