objectiveC/CMTime - convert AVPlayer.duration to milliseconds

nano picture nano · May 11, 2011 · Viewed 24.5k times · Source

I'm creating an app for playing a ringtone and I'd want to know the current time in milliseconds of the played ringtone every time.

CMTime cTime = player_.currentTime; float currentTime = cTime.value / cTime.timescale;

That currentTime here gets the value in seconds. How can I get the exact currentTime value but in milliseconds?

Answer

Samssonart picture Samssonart · Jul 11, 2011

There is a way to get current times in seconds, you can take 1000 times that and ther you have your miliseconds:

Float64 dur = CMTimeGetSeconds([player currentTime]);
Float64 durInMiliSec = 1000*dur;

Sadly you will have to use it as a float or Float64 you can't use that result as a CMTime