Why AVPlayer returns video duration (seconds) as Double?

I need to get video duration in seconds. If I use code below

 guard let playerItem = self.player?.currentItem else { return 0 }
print("playerItem.duration", playerItem.duration, playerItem.duration.seconds, playerItem.duration.toString)

it returns me a double value 37.568

CMTime(value: 37568, timescale: 1000, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0) 37.568 00:00:37

I wonder why it's a 37.568 instead of 37.000? if video is 00:00:37?

Does it means, it is a 37,5s long?

Accepted Reply

an AVPlayerItem has a duration property, of type CMTime. CMTime does not have a .toString property, it looks like a member of your team wrote an extension on CMTime to provide such a property. Your confusion probably arises because that extension chose to only display whole seconds. Your video really has a duration of 37,568 ticks of a 1/1000s clock.

Replies

Yes.

an AVPlayerItem has a duration property, of type CMTime. CMTime does not have a .toString property, it looks like a member of your team wrote an extension on CMTime to provide such a property. Your confusion probably arises because that extension chose to only display whole seconds. Your video really has a duration of 37,568 ticks of a 1/1000s clock.