An object that simplifies the playing of looping media content using a queue player.


class AVPlayerLooper : NSObject


You can manually implement looping playback in your app using AVQueuePlayer, but AVPlayerLooper provides a much simpler interface to loop a single AVPlayerItem. You create a player looper by passing it a reference to your AVQueuePlayer and a template AVPlayerItem and the looper automatically manages the looping playback of this content (see example).

let asset = // AVAsset with its 'duration' property value loaded
let playerItem = AVPlayerItem(asset: asset)
// Create a new player looper with the queue player and template item
playerLooper = AVPlayerLooper(player: queuePlayer, templateItem: playerItem)
// Begin looping playback


Creating a Player Looper

init(player: AVQueuePlayer, templateItem: AVPlayerItem, timeRange: CMTimeRange)

Creates a player looper instance to repeat the specified time range of a player item using a queue player.

init(player: AVQueuePlayer, templateItem: AVPlayerItem)

Returns a player looper instance configured to loop the full duration of the specified player item in the queue player.

Configuring the Player Looper

var loopingPlayerItems: [AVPlayerItem]

An array containing replicas of the template player item used to accomplish the looping.

func disableLooping()

Disables looping for the player queue.

Observing Looper State

var loopCount: Int

The number of times the specified player item has been played.

var status: AVPlayerLooper.Status

A status indicating the loopers ability to be used for looping playback.

enum AVPlayerLooper.Status

The statuses that indicate whether a looper can successfully perform looping playback.

var error: Error?

The error that caused looping to fail.


Inherits From

Conforms To