Created
September 22, 2020 02:08
-
-
Save theoknock/db16e20aa7bc36d90612b2cdba562b9c to your computer and use it in GitHub Desktop.
Converting current CMTime to NSString
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef CMTime(^CurrentCMTime)(void); | |
static CurrentCMTime _Nonnull current_cmtime = ^ CMTime (void) { | |
return CMClockGetTime(CMClockGetHostTimeClock()); | |
}; | |
typedef NSString * _Nonnull (^StringFromTime)(CMTime); | |
static StringFromTime _Nonnull cmTimeString = ^ NSString * (CMTime cm_time) { | |
NSString *stringFromCMTime; | |
float seconds = round(CMTimeGetSeconds(cm_time)); | |
int hh = (int)floorf(seconds / 3600.0f); | |
int mm = (int)floorf((seconds - hh * 3600.0f) / 60.0f); | |
int ss = (((int)seconds) % 60); | |
if (hh > 0) | |
{ | |
stringFromCMTime = [NSString stringWithFormat:@"%02d:%02d:%02d", hh, mm, ss]; | |
} | |
else | |
{ | |
stringFromCMTime = [NSString stringWithFormat:@"%02d:%02d", mm, ss]; | |
} | |
return stringFromCMTime; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment