Instance Method

seek(to:toleranceBefore:toleranceAfter:completionHandler:)

Sets the current playback time within a specified time bound and invokes the specified block when the seek operation has either been completed or been interrupted.

Declaration

func seek(to time: CMTime, toleranceBefore: CMTime, toleranceAfter: CMTime, completionHandler: @escaping (Bool) -> Void)

Parameters

time

The time to which to seek.

toleranceBefore

The tolerance allowed before time.

toleranceAfter

The tolerance allowed after time.

completionHandler

The block to invoke when the seek operation has either been completed or been interrupted.

The block takes one argument:

finished

Indicated whether the seek operation completed.

Discussion

Use this method to seek to a specified time for the current player item and to be notified when the seek operation is complete.

The time seeked to will be within the range [time-beforeTolerance, time+afterTolerance], and may differ from the specified time for efficiency. You can request sample accurate seeking by passing a time value ofkCMTimeZero for both toleranceBefore and toleranceAfter. Sample accurate seeking may incur additional decoding delay which can impact seeking performance.

Invoking this method with toleranceBefore set to kCMTimePositiveInfinity and toleranceAfter set to kCMTimePositiveInfinity is the same as invoking seek(to:).

The completion handler for any prior seek request that is still in process will be invoked immediately with the finished parameter set to false. If the new request completes without being interrupted by another seek request or by any other operation the specified completion handler will be invoked with the finished parameter set to true.

See Also

Managing Time

func currentTime()

Returns the current time of the current player item.

func seek(to: CMTime)

Sets the current playback time to the specified time.

func seek(to: Date)

Sets the current playback time to the time specified by the date object.

func seek(to: CMTime, completionHandler: (Bool) -> Void)

Sets the current playback time to the specified time and executes the specified block when the seek operation has either been completed or been interrupted.

func seek(to: Date, completionHandler: (Bool) -> Void)

Sets the current playback time to the specified time and executes the specified block when the seek operation completes or is interrupted.

func seek(to: CMTime, toleranceBefore: CMTime, toleranceAfter: CMTime)

Sets the current playback time within a specified time bound.