How to pass float value where datatype is CMTime?

Developer picture Developer · Dec 27, 2012 · Viewed 8.4k times · Source

I am creating an application in which I have to mix the songs. I have accomplished this but the problem is when I am using the following function.

- (BOOL)insertTimeRange:(CMTimeRange)timeRange ofTrack:(AVAssetTrack *)track atTime:(CMTime)startTime error:(NSError **)error;

I have to pass CMTime type value in the atTime parameter but it doesn't takes Float value and I have to add the another song at some floating point value. Is it possible any how?

Answer

user529758 picture user529758 · Dec 27, 2012

You can use one of the CMTimeMake...() functions. You have to supply a time point and a timescale value. The former is a 64-bit integer; you can just truncate or round your float to convert it to an integer, or use a necessarily high timescale:

CMTime tm = CMTimeMake(53425, 10000); // @ 5.3425 sec