Class

AVPlayerLayer

An object that manages a player's visual output.

Declaration

class AVPlayerLayer : CALayer

Overview

A convenient way of using AVPlayerLayer in iOS or tvOS is as the backing layer for a UIView as illustrated in the following code example:

class PlayerView: UIView {
    var player: AVPlayer? {
        get {
            return playerLayer.player
        }
        set {
            playerLayer.player = newValue
        }
    }
    
    var playerLayer: AVPlayerLayer {
        return layer as! AVPlayerLayer
    }
    
    // Override UIView property
    override static var layerClass: AnyClass {
        return AVPlayerLayer.self
    }
}

Topics

Creating a Player Layer

init(player: AVPlayer?)

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

Configuring Player Layer Values

var player: AVPlayer?

The player for which the player layer displays visual output.

var isReadyForDisplay: Bool

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

var videoGravity: AVLayerVideoGravity

A value that specifies how the video is displayed within a player layer’s bounds.

struct AVLayerVideoGravity

A value that defines how the video is displayed within a layer’s bounds rectangle.

var videoRect: CGRect

The current size and position of the video image as displayed within the receiver's bounds.

var pixelBufferAttributes: [String : Any]?

The client requirements for the visual output displayed in the player layer during playback.

func AVMakeRect(aspectRatio: CGSize, insideRect: CGRect) -> CGRect

Returns a scaled CGRect that maintains the aspect ratio specified by a CGSize within a bounding CGRect.

Relationships

Inherits From

Conforms To

See Also

Media Playback

class AVPlayer

An object that provides the interface to control the player’s transport behavior.

class AVQueuePlayer

A player used to play a number of items in sequence.

class AVPlayerItem

An object used to model the timing and presentation state of an asset played by the player.

class AVPlayerItemTrack

An object used to modify the presentation state of an asset track being presented by a player.

class AVSynchronizedLayer

An object used to synchronize with a specific player item.

class AVPlayerItemMetadataCollector

An object used to capture the date range metadata defined for an HTTP Live Streaming asset.

class AVPlayerMediaSelectionCriteria

An object that specifies the preferred languages and media characteristics for a player.

class AVSampleBufferAudioRenderer

An object used to decompress audio and play compressed or uncompressed audio.

class AVSampleBufferDisplayLayer

An object that displays compressed or uncompressed video frames.

class AVSampleBufferRenderSynchronizer

An object used to synchronize multiple queued sample buffers to a single timeline.