     
     fileprivate func updateCurrentTimeLabelWithTime(time: TimeInterval) {
         if self.currentTimeLabel == nil { return }
-        self.currentTimeLabel?.text = timecodeForTimeInterval(time: time)
+        self.currentTimeLabel.text = timecodeForTimeInterval(time: time)
     }
     
     fileprivate func updateDurationLabelWithTime(time: TimeInterval) {
         if self.durationLabel == nil { return }
-        self.durationLabel?.text = timecodeForTimeInterval(time: time)
+        self.durationLabel.text = timecodeForTimeInterval(time: time)
     }
     
     fileprivate func updateRemainingTimeLabelWithTime(time: TimeInterval) {
         if self.remainingTimeLabel == nil { return }
-        self.remainingTimeLabel?.text = timecodeForTimeInterval(time: time)
+        self.remainingTimeLabel.text = timecodeForTimeInterval(time: time)
     }
     
     fileprivate func timecodeForTimeInterval(time: TimeInterval) -> String {


class SHVideoPlayerScrubber: NSObject {
    
    var slider: UISlider? { get {
            return slider
        } set {
            setSliderTapAction()
            setSliderValueChangeAction()
        }
    }
    var currentTimeLabel: UILabel?
    var durationLabel: UILabel?
    var remainingTimeLabel: UILabel?
    
    var player: AVPlayer! { get { return player }
        set {
            self.player.pause()
            removeTimeObserver()
            self.framesPerSecond = nominalFrameRateForPlayer()
            setupTimeObserver()
            updateCurrentTimeLabelWithTime(time: 0)
            var duration = self.player.currentItem?.duration
            if !CMTIME_IS_VALID(duration!) || CMTIME_IS_INDEFINITE(duration!) {
                self.player.currentItem?.addObserver(self, forKeyPath: SHVideoPlayerConstants.ObserverKey.duration, options: .new, context: nil)
            }
        }
    }
    
    fileprivate var playAfterDrag: Bool = true
    fileprivate var timeObserver: Any?
    fileprivate var framesPerSecond: Float = 0.0
    
    fileprivate func setSliderTapAction() {
        if self.slider == nil { return }
        let gesture = UITapGestureRecognizer(target: self, action: #selector(sliderTapAction))
        slider?.addGestureRecognizer(gesture)
    }
    
    fileprivate func setSliderValueChangeAction() {
        slider?.addTarget(self, action: #selector(sliderValueChangeAction), for: .valueChanged)
    }
    
    fileprivate func setupTimeObserver() {

        })
    }
    
    //MARK: actions 
    
    @objc fileprivate func sliderTapAction(gesture: UITapGestureRecognizer) {
        if self.slider.isHighlighted { return }
        var isPlaying = self.player.rate > 0
        var trackRect = self.slider.trackRect(forBounds: self.slider.bounds)
        var thumbRect = self.slider.thumbRect(forBounds: self.slider.bounds, trackRect: trackRect, value: 0)
        var thumbWidth = thumbRect.size.width
        var point = gesture.location(in: self.slider)
        var ratio: Float = 0.0
        if point.x > thumbWidth / 2 { ratio = 0.0 }
        else if point.x > (self.slider.bounds.size.width - thumbWidth / 2) {
            ratio  = 1.0
        } else {
            ratio = Float((point.x - thumbWidth / 2) / (self.slider.bounds.size.width - thumbWidth))
        }
        var del = ratio * (self.slider.maximumValue - self.slider.minimumValue)
        var value = self.slider.maximumValue + del;
        self.slider.setValue(value, animated: true)
        updatePlayer(playIfNeeded: isPlaying)
    }
    
