我有一个小整数值,我想把它转换成CMTime。
问题是
CMTime(值:_,timeScale:_)
或
CMTimeMakeWithSeconds(值:_,timeScale:_)
将始终返回地板,以便时间总是等于0.0 seconds
let smallValue = 0.0401588716
let frameTime = CMTime(Int64(smallValue) , timeScale: 1)
//frameTime is 0.0 seconds because of Int64 conversion
let frameTimeInSeconds = CMTimeMakeWithSeconds(smallValue , timeScale: 1)
// frameTimeInSeconds also returns 0.0 seconds.发布于 2017-02-23 08:44:18
CMTime将时间值表示为带有整数分子( value)和分母( timescale)的有理数。为了表示像您这样的小值,您必须选择更大的时间刻度(取决于所需的精度)。示例:
let smallValue = 0.0401588716
let frameTime = CMTime(seconds: smallValue, preferredTimescale: 1000000)
print(frameTime.seconds) // 0.040158发布于 2017-02-23 08:51:23
在发表这个问题之前,我应该先考虑一下。
let smallValue = 0.0401588716
let oneSec = CMTimeMakeWithSeconds(1, timeScale: 1)
let frameTime = CMTimeMultiplyByFloat64(oneSec , smallValue)
print(CMTimeGetSeconds(frameTime)) // 0.040158872https://stackoverflow.com/questions/42410190
复制相似问题