iOS Developer Library — Prerelease

Developer

AV Foundation Framework Reference AVPlayerLayer Class Reference

Options
Deployment Target:

On This Page
Language:

AVPlayerLayer

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:

  1. AVPlayer *player = <#A configured AVPlayer object#>;
  2. CALayer *superlayer = <#Get a CALayer#>;
  3. AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
  4. [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.

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

    Declaration

    Swift

    init(player player: AVPlayer?)

    Objective-C

    + (AVPlayerLayer * nonnull)playerLayerWithPlayer:(AVPlayer * nullable)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.

  • The player for which the player layer displays visual output.

    Declaration

    Swift

    var player: AVPlayer?

    Objective-C

    @property(nonatomic, retain) AVPlayer *player

    Availability

    Available in iOS 4.0 and later.

  • 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)

    Declaration

    Swift

    var readyForDisplay: Bool { get }

    Objective-C

    @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 NOfalse, however the layer will not have any user-visible content until the value becomes YEStrue.

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

    Availability

    Available in iOS 4.0 and later.

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

    Declaration

    Swift

    var videoGravity: String

    Objective-C

    @property(copy) NSString *videoGravity

    Discussion

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

    This property is animatable.

    Availability

    Available in iOS 4.0 and later.

    See Also

    bounds (CALayer)

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

    Declaration

    Swift

    var videoRect: CGRect { get }

    Objective-C

    @property(nonatomic, readonly) CGRect videoRect

    Availability

    Available in iOS 7.0 and later.