我在几秒钟内获得当前的游戏 Value ,但我需要几毫秒 . 我试过currentTime.value / currentTime.scale . 但它并没有得到确切的 Value .
CMTime currentTime = vPlayer.currentItem.currentTime; //playing time
CMTimeValue tValue=currentTime.value;
CMTimeScale tScale=currentTime.timescale;
NSTimeInterval time = CMTimeGetSeconds(currentTime);
NSLog(@"Time :%f",time);//This is in seconds, it misses decimal value double shot=(float)tValue/(float)tScale;
shotTimeVideo=[NSString stringWithFormat:@"%.2f",(float)tValue/(float)tScale];
CMTime currentTime = vPlayer.currentItem.currentTime; //playing time
CMTimeValue tValue=currentTime.value;
CMTimeScale tScale=currentTime.timescale;
NSTimeInterval time = CMTimeGetSeconds(currentTime);
NSLog(@"Time :%f",time);//This is in seconds, it misses decimal value
double shot=(float)tValue/(float)tScale;
shotTimeVideo=[NSString stringWithFormat:@"%.2f", (float)tValue/(float)tScale];
1 回答
好吧,首先,你想要的 Value 是millisecond而不是秒
所以,你可以使用 CMTimeGetSeconds(<#CMTime time#>) 获得秒
然后,如果你想要毫秒,请使用秒/ 1000.f表示浮点数或双精度值
用于CMTime计算使用CMTime方法
CMTimeMultiplyByRatio(<#CMTime time#>,<#int32_t multiplier#>,<#int32_t divisor#>)
这样做 - > CMTimeMultiplyByRatio(yourCMTimeValue,1,1000)
Apple's Doc