     /// Pauses audio player. Calling play() will resume from the paused time.
     public func pause() {
         guard isPlaying, !isPaused else { return }
-
+        stoppedTime = getCurrentTime()
         playerNode.pause()
         isPaused = true
+    }
+    
+    /// Gets the accurate playhead time regardless of seeking and pausing
+    /// Can't be relied on if playerNode has its playstate modified directly
+    public func getCurrentTime() -> TimeInterval {
+        if let nodeTime = self.playerNode.lastRenderTime, let playerTime = self.playerNode.playerTime(forNodeTime: nodeTime) {
+           return Double(Double(playerTime.sampleTime) / playerTime.sampleRate) + segmentStartTime
+        }
+        return stoppedTime
     }
 }
 

    public var duration: TimeInterval {
        bufferDuration ?? file?.duration ?? 0
    }

    /// Completion handler to be called when file or buffer is done playing.
    /// This also will be called when looping from disk,

        self.file = file
        schedule(at: when)
    }
    
    /// Sets the player's audio file to a certain time in the track (in seconds)
    /// and respects the players current play state
    /// - Parameters:
    ///   - time seconds into the audio file to set playhead
    public func seek(time: Float){
        let wasPlaying = self.isPlaying
        self.playerNode.stop()
        if let audioFile = self.file {
            let sampleLength = audioFile.length
            let processingFormat = audioFile.processingFormat
            let sampleRate = Float(processingFormat.sampleRate)
            let startSample = floor(time * sampleRate)
            let lengthSamples = Float(sampleLength) - startSample
            
            self.playerNode.scheduleSegment(audioFile,
                                   startingFrame: AVAudioFramePosition(startSample),
                                   frameCount: AVAudioFrameCount(lengthSamples),
                                   at: nil,
                                   completionHandler: {
                                    self.playerNode.pause()
                                   })
            self.segmentStartTime = TimeInterval(time)
        }
        if wasPlaying && !isPaused {
            self.playerNode.play()
        } else {
            self.stoppedTime = TimeInterval(time)
        }
    }
}
