From e96cbf6337ca70c64545df8007785b755dada3f4 Mon Sep 17 00:00:00 2001 From: David Chavez Date: Wed, 30 Jan 2019 20:39:19 +0100 Subject: [PATCH] Get duration directly from asset It is more reliable because the current item directly will return NaN depending on what's loaded. --- SwiftAudio/Classes/AVPlayerWrapper/AVPlayerWrapper.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SwiftAudio/Classes/AVPlayerWrapper/AVPlayerWrapper.swift b/SwiftAudio/Classes/AVPlayerWrapper/AVPlayerWrapper.swift index abcdcc1..fae56d9 100755 --- a/SwiftAudio/Classes/AVPlayerWrapper/AVPlayerWrapper.swift +++ b/SwiftAudio/Classes/AVPlayerWrapper/AVPlayerWrapper.swift @@ -85,7 +85,10 @@ class AVPlayerWrapper: AVPlayerWrapperProtocol { } var duration: TimeInterval { - if let seconds = currentItem?.duration.seconds, !seconds.isNaN { + if let seconds = currentItem?.asset.duration.seconds, !seconds.isNaN { + return seconds + } + else if let seconds = currentItem?.duration.seconds, !seconds.isNaN { return seconds } else if let seconds = currentItem?.loadedTimeRanges.first?.timeRangeValue.duration.seconds,