---
title: "setRate(_:time:atHostTime:)"
framework: avfoundation
role: symbol
role_heading: Instance Method
path: "avfoundation/avplayer/setrate(_:time:athosttime:)"
---

# setRate(_:time:atHostTime:)

Synchronizes the playback rate and time of the current item with an external source.

## Declaration

```swift
nonisolated func setRate(_ rate: Float, time itemTime: CMTime, atHostTime hostClockTime: CMTime)
```

## Parameters

- `rate`: The playback rate for the item.
- `itemTime`: The precise time at which to match playback of the item. To use the current item’s current time, specify doc://com.apple.documentation/documentation/CoreMedia/CMTime/invalid.
- `hostClockTime`: The host time at which to synchronize playback. If you specify doc://com.apple.documentation/documentation/CoreMedia/CMTime/invalid, the rate and time are set together without any external synchronization.

## Discussion

Discussion This method adjusts the current item’s timebase so that the time in itemTime is in sync with the time in hostClockTime. Thus, if hostClockTime specifies a time in the past, the item’s timebase is adjusted to make it appear as if the item has been running at the specified rate since itemTime. And if hostClockTime specifies a time in the future, playback is adjusted backward (if possible) so that the value in itemTime occurs at the precise moment the host’s clock reaches the value in hostClockTime. If there is no content to play before the time specified by itemTime, playback holds until the two times come into sync. This method does not ensure that media data is loaded before the timebase starts moving. However, if you specify a host time in the near future, that would give you some time to load the media data and prepare for playback. important: The value of automaticallyWaitsToMinimizeStalling must be set to false before calling this method. If the property value is true, calling this method results in the system raising an invalid argument exception.

## See Also

### Synchronizing multiple players

- [preroll(atRate:completionHandler:)](avfoundation/avplayer/preroll(atrate:completionhandler:).md)
- [cancelPendingPrerolls()](avfoundation/avplayer/cancelpendingprerolls().md)
- [sourceClock](avfoundation/avplayer/sourceclock.md)
- [masterClock](avfoundation/avplayer/masterclock.md)
