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


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



The queue player to use for playback. The player must not be nil.


The player item to loop, which must not be nil.


The player item time range to loop. Passing a value of invalid is equivalent to a time range of [0, player item’s duration].

Return Value

An new instance of AVPlayerLooper.


The player item you specify will be used as a template to generate at least 3 player item replicas that will be inserted into the specified player’s queue to accomplish the looping playback. As the player item will only be used as a template, and not for actual playback, any changes you make to the player item after initialization will not be reflected in the replicas. If you need to explicitly configure the replica player items, such as adding instances of AVPlayerItemOutput to them, you can access them through the loopingPlayerItems property.

You should not modify the player’s queue while AVPlayerLooper is performing looping playback. If you need to perform any additional configuration of the player prior to playback, you should set its rate to 0.0, perform the required configuration, and then begin playback once the configuration is complete.

The CMTimeRange you specify will limit each item’s loop iteration to playing within the specified time range. To loop the full duration of the asset, specify a time range value of invalid for the timeRange parameter. Time range looping will be accomplished by seeking to the time range’s start time and setting player item’s forwardPlaybackEndTime property on the looping item replicas.

See Also

Creating a Player Looper

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.