我正在创建一个用于播放铃声的应用程序,我想知道每次播放铃声的当前时间(以毫秒为单位)。
CMTime cTime =player_.currentTime; float currentTime = cTime.value/cTime.timescale;
此处的 currentTime 获取以秒为单位的值。 如何获得精确的 currentTime 值(以毫秒为单位)?
最佳答案
有一种方法可以获取当前时间(以秒为单位),您可以将其乘以 1000 倍,然后得到毫秒:
Float64 dur = CMTimeGetSeconds([player currentTime]);
Float64 durInMiliSec = 1000*dur;
遗憾的是,您必须将其用作float
或Float64
,您不能将该结果用作CMTime
关于iphone - ObjectiveC/CMTime - 将 AVPlayer.duration 转换为毫秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5966665/