<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFoundation",
  "identifier" : "/documentation/AVFoundation/AVPlayer/addPeriodicTimeObserver(forInterval:queue:using:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(cs)AVPlayer(im)addPeriodicTimeObserverForInterval:queue:usingBlock:"
  },
  "title" : "addPeriodicTimeObserver(forInterval:queue:using:)"
}
-->

# addPeriodicTimeObserver(forInterval:queue:using:)

Requests the periodic invocation of a given block during playback to report changing time.

```
nonisolated func addPeriodicTimeObserver(forInterval interval: CMTime, queue: dispatch_queue_t?, using block: @escaping @Sendable (CMTime) -> Void) -> Any
```

## Parameters

`interval`

The time interval at which the system invokes the block during normal playback, according to progress of the player’s current time.

`queue`

The dispatch queue on which the system calls the block. Passing a concurrent queue isn’t supported and results in undefined behavior.

    If you pass     `NULL`    , the system uses the main queue.

`block`

The block that the system periodically invokes.

    The block takes a single parameter:

- time: The time at which the system invokes the block.

## Return Value

An opaque object that you pass as the argument to [`removeTimeObserver(_:)`](/documentation/AVFoundation/AVPlayer/removeTimeObserver(_:)) to cancel observation.

## Discussion

You must maintain a strong reference to the returned value as long as you want the time observer to be invoked by the player. You must pair each invocation of this method with a corresponding call to [`removeTimeObserver(_:)`](/documentation/AVFoundation/AVPlayer/removeTimeObserver(_:)). Releasing the observer object without invoking [`removeTimeObserver(_:)`](/documentation/AVFoundation/AVPlayer/removeTimeObserver(_:)) results in undefined behavior.

The system invokes the block periodically at the interval specified, interpreted according to the timeline of the current item. It also invokes the block whenever time jumps or playback starts or stops. If the interval corresponds to a very short interval in real time, the player may invoke the block less frequently than your app requested. Even so, the player will invoke the block sufficiently often for the client to update indications of the current time appropriately in its end-user interface.

The following example illustrates how you set up a callback the system invokes every half second during normal playback.

```swift
func addPeriodicTimeObserver() {
    // Invoke callback every half second
    let interval = CMTime(seconds: 0.5,
                          preferredTimescale: CMTimeScale(NSEC_PER_SEC))
    // Add time observer. Invoke closure on the main queue.
    timeObserverToken =
        player.addPeriodicTimeObserver(forInterval: interval, queue: .main) {
            [weak self] time in
            // update player transport UI
    }
}
```

> Important:
> Use a `weak` reference to `self` in the callback block to prevent creating a retain cycle.

---

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)