     
     @objc fileprivate func playPauseButtonAction(button: UIButton) {
         if self.player.rate == 0 {
-            if self.player.currentTime() == self.player.currentItem?.duration {
-                // replaying video
-                self.player.seek(to: kCMTimeZero, completionHandler: { (done: Bool) in
-                    self.play()
-                })
-            } else {
+            self.resumeOrPlayAction()
+        } else {
+            self.pause()
+        }
+    }
+    
+    private func resumeOrPlayAction() {
+        if self.player.currentTime() == self.player.currentItem?.duration {
+            // replaying video
+            self.player.seek(to: kCMTimeZero, completionHandler: { (done: Bool) in
                 self.play()
-            }
-        } else {
-            self.pause()
+            })
+        } else {
+            self.play()
         }
     }
     

    }
    
    fileprivate func playerTimeChanged() {
        if self.player.currentItem == nil { return }
        let secondsElapsed = CMTimeGetSeconds(self.player.currentItem!.currentTime())
        var duratoinInSeconds = 0.0
        var ratio = 0.0
        if CMTIME_IS_VALID((self.player.currentItem?.duration)!) && !CMTIME_IS_INDEFINITE((self.player.currentItem?.duration)!) {
           duratoinInSeconds = CMTimeGetSeconds((self.player.currentItem?.duration)!)
        }
        
        if duratoinInSeconds > 0 {
            ratio = secondsElapsed / duratoinInSeconds
            updateDurationLabelWithTime(time: duratoinInSeconds)

    
    override public func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        if keyPath == SHVideoPlayerConstants.ObserverKey.duration {
            guard let currentItem = self.player.currentItem else {
                print("players current item is nil")
                return
            }
            if CMTIME_IS_VALID(currentItem.duration) && !CMTIME_IS_INDEFINITE(currentItem.duration) {
                removeCurrentItemObserver()
                playerTimeChanged()
            }
