4

Is there any method to check a CMTime is equal to another CMTime. In my case I need to check CMTime is equal to KCMTimeZero. I tried CMTimeCompare method, but it will be True for all the CMTimes which is equal to KCMTimeZero or greater than KCMTimeZero.

Vishnu Kumar. S
  • 1,797
  • 1
  • 15
  • 35

3 Answers3

10

I found the following way to check by converting it to seconds

if(CMTimeGetSeconds(myTime) == CMTimeGetSeconds(kCMTimeZero))
{
     // do something...     
}
Vishnu Kumar. S
  • 1,797
  • 1
  • 15
  • 35
7

CMTimeCompare does that trick,

from Xcode's documentation CMTimeReference:

int32_t CMTimeCompare ( CMTime time1, CMTime time2 );

Return Value
The numerical relationship of the two CMTimes.

  • -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.
2

I prefer using CMTIME_COMPARE_INLINE macro defined in CMTime.h to keep code more readable. Here is the code for your case (comparison with kCMTimeZero):

if (CMTIME_COMPARE_INLINE(myTime, ==, kCMTimeZero))
{
    // Your code here
}
Akhrameev
  • 325
  • 4
  • 12