     }
     
     fileprivate func addPlayerItemPlayDurationObserver() {
-        let duration = self.player.currentItem?.duration
-        if !CMTIME_IS_VALID(duration!) || CMTIME_IS_INDEFINITE(duration!) {
+        guard let duration = self.player.currentItem?.duration else {
+            print("duration is nil")
+            return
+        }
+        if !CMTIME_IS_VALID(duration) || CMTIME_IS_INDEFINITE(duration) {
             self.player.currentItem?.addObserver(self, forKeyPath: SHVideoPlayerConstants.ObserverKey.duration, options: .new, context: nil)
         }
     }

    
    @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.play()
            }
        } else {
            self.pause()
        }
    }
    

        timeObserver = nil
    }
    
    fileprivate func nominalFrameRateForPlayer() -> Float {
        var track: AVAssetTrack? = nil
        if let tracks = self.player.currentItem?.asset.tracks(withMediaType: AVMediaTypeVideo) {
            if tracks.count != 0 {
                track = tracks[0]
            }
        }
        return track.nominalFrameRate ?? 0.0
    }
    
    fileprivate func updateCurrentTimeLabelWithTime(time: TimeInterval) {
