<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.12.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFoundation",
  "identifier" : "/documentation/AVFoundation/AVPlayerLooper/init(player:templateItem:timeRange:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(cs)AVPlayerLooper(im)initWithPlayer:templateItem:timeRange:"
  },
  "title" : "init(player:templateItem:timeRange:)"
}
-->

# init(player:templateItem:timeRange:)

Creates a player looper that continuously plays the specified time range of a player item.

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

## Parameters

`player`

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

`itemToLoop`

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

`loopRange`

The player item time range to loop. Passing a value of <doc://com.apple.documentation/documentation/CoreMedia/CMTimeRange/invalid> is equivalent to a time range of [0, player item’s duration].

## Return Value

An new instance of `AVPlayerLooper`.

## Discussion

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`](/documentation/AVFoundation/AVPlayerItemOutput) to them, you can access them through the [`loopingPlayerItems`](/documentation/AVFoundation/AVPlayerLooper/loopingPlayerItems) property.

> Important:
> The specified player item’s asset should have its ``doc://com.apple.avfoundation/documentation/AVFoundation/AVAsset/duration`` property loaded before you initialize this class so that initialization will not be blocked while waiting for the ``doc://com.apple.avfoundation/documentation/AVFoundation/AVAsset/duration`` to become known. An <doc://com.apple.documentation/documentation/Foundation/NSExceptionName/invalidArgumentException> will be raised if the player item has a duration of 0.

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`](/documentation/AVFoundation/AVPlayer/rate) to `0.0`, perform the required configuration, and then begin playback once the configuration is complete.

The <doc://com.apple.documentation/documentation/CoreMedia/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 <doc://com.apple.documentation/documentation/CoreMedia/CMTimeRange/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`](/documentation/AVFoundation/AVPlayerItem/forwardPlaybackEndTime) property on the looping item replicas.

> Important:
> An <doc://com.apple.documentation/documentation/Foundation/NSExceptionName/invalidArgumentException> will be raised if the time range you specify has a duration of 0 or is not contained within the time range of the template player item.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)