Function

CMTimeCompare(_:_:)

Returns the numerical relationship of two CMTimes.

Declaration

func CMTimeCompare(_ time1: CMTime, _ time2: CMTime) -> Int32

Parameters

time1

First CMTime in comparison.

time2

Second CMTime in comparison.

Return Value

The numerical relationship of the two CMTime structs is as follows:

  • -1 is returned if time1 is less than time2.

  • 1 is returned if time1 is greater than time2.

  • 0 is returned if time1 and time2 are equal.

Discussion

When comparing CMTimes, it is recommended to use CMTIME_COMPARE_INLINE macro since it makes comparison expressions much more readable by putting the comparison operation between the operands.

If the two CMTimes are numeric (i.e.. not invalid, infinite, or indefinite), and have different epochs, it is considered that times in numerically larger epochs are always greater than times in numerically smaller epochs. Since this routine will be used to sort lists by time, it needs to give all values (even invalid and indefinite ones) a strict ordering to guarantee that sort algorithms terminate safely. The order chosen is somewhat arbitrary: -infinity < all finite values < indefinite < +infinity < invalid

Invalid CMTimes are considered to be equal to other invalid CMTimes, and greater than any other CMTime. Positive infinity is considered to be less than any invalid CMTime, equal to itself, and greater than any other CMTime. An indefinite CMTime is considered to be less than any invalid CMTime, less than positive infinity, equal to itself, and greater than any other CMTime. Negative infinity is considered to be equal to itself, and less than any other CMTime.

See Also

Inspecting and Evaluating Times

func CMTimeAbsoluteValue(CMTime) -> CMTime

Returns the absolute value of a CMTime.

func CMTimeGetSeconds(CMTime) -> Float64

Converts a CMTime to seconds.

func CMTimeMaximum(CMTime, CMTime) -> CMTime

Returns the greater of two CMTimes (as defined by CMTimeCompare(_:_:)).

func CMTimeMinimum(CMTime, CMTime) -> CMTime

Returns the lesser of two CMTimes (as defined by CMTimeCompare(_:_:)).

func CMTIME_IS_VALID(CMTime) -> Bool

Returns a Boolean value that indicates whether a given time is valid.

func CMTIME_IS_INVALID(CMTime) -> Bool

Returns a Boolean value that indicates whether a given time is invalid.

func CMTIME_IS_POSITIVEINFINITY(CMTime) -> Bool

Returns a Boolean value that indicates whether a given time is positive infinity.

func CMTIME_IS_NEGATIVEINFINITY(CMTime) -> Bool

Returns a Boolean value that indicates whether a given time is negative infinity.

func CMTIME_IS_INDEFINITE(CMTime) -> Bool

Returns a Boolean value that indicates whether a given time is indefinite.

func CMTIME_IS_NUMERIC(CMTime) -> Bool

Returns a Boolean value that indicates whether a given time is numeric.

func CMTIME_HAS_BEEN_ROUNDED(CMTime) -> Bool

Returns a Boolean value that indicates whether a given time has been rounded.