setRate(_:time:atHostTime:)
Synchronizes the playback rate and time of the current item with an external source.
Declaration
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 Invalid.
- hostClockTime:
The host time at which to synchronize playback. If you specify Invalid, the rate and time are set together without any external synchronization.
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.