Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert TimeInterval to CMTime in Swift 4?

Tags:

swift

I can’t seem to figure out how to convert TimeInterval to CMTime. Does it need more than just a simple conversion method?

like image 585
Colin FB Avatar asked Jul 16 '18 00:07

Colin FB


1 Answers

You can write something like this:

let timeIntvl: TimeInterval = 60
let cmTime = CMTime(seconds: timeIntvl, preferredTimescale: 1000000)

1000000 represents that the preferred Timescale is 1μsec (1/1000000 sec).

When you convert between some types, there's usually no simple conversion method and you may need to find an initializer of the destination type.

init(seconds: Double, preferredTimescale: CMTimeScale)

like image 91
OOPer Avatar answered Nov 07 '22 21:11

OOPer