             let dur = self.audioPlayer.duration
             self.duration.text = Int64(dur).toMediaPlayerString()
             self.progress.value = Float(playbackPosition / dur)
+            
+            if let endTimePreview = self.endTimePreview {
+                if Int(self.audioPlayer.progress) >= endTimePreview {
+                    self.pvMediaPlayer.pause()
+                    self.endTimePreview = nil
+                }
+            }
         }
     }
     

    
    let audioPlayer = PVMediaPlayer.shared.audioPlayer
    var endTime: Int?
    var playerHistoryItem: PlayerHistoryItem?
    let pvMediaPlayer = PVMediaPlayer.shared
    var startTime: Int?

    @IBOutlet weak var startTimeInput: UITextField!
    
    @IBAction func sliderAction(_ sender: UISlider) {
        let duration = self.audioPlayer.duration
        let newTime = Double(sender.value) * duration
        self.audioPlayer.seek(toTime: newTime)
        updateTime()
    }
    
    @IBAction func startTimePreview(_ sender: Any) {
        if let startTime = self.startTime {
            self.audioPlayer.seek(toTime: Double(startTime))
            self.pvMediaPlayer.play()
        }
    }
    
    @IBAction func endTimePreview(_ sender: Any) {
        if let endTime = self.endTime {
            self.endTimePreview = endTime
            
            if endTime < 3 {
                self.audioPlayer.seek(toTime: 0)
            } else {
                self.audioPlayer.seek(toTime: Double(endTime) - 3)
            }
            
            self.pvMediaPlayer.play()
        }
    }
    
    @IBAction func play(_ sender: Any) {
