11using System ;
2+ using System . Diagnostics ;
23using System . Threading ;
34using System . Windows ;
45using System . Windows . Threading ;
@@ -17,7 +18,9 @@ public partial class MainWindow : Window
1718 double volume ;
1819 double prevVolume ;
1920 bool ProgressSliderChanging = false ;
20- string path ;
21+ double LastProgressSliderThumbDeltaValue = 0 ;
22+ Stopwatch LastProgressSliderDeltaEvent = new Stopwatch ( ) ;
23+ string path ;
2124 Thread LoopingThread ;
2225
2326
@@ -149,11 +152,36 @@ private void Close(object sender, System.ComponentModel.CancelEventArgs e)
149152 private void Progress_Slider_DragStarted ( object sender , System . Windows . Controls . Primitives . DragStartedEventArgs e )
150153 {
151154 ProgressSliderChanging = true ;
155+ double NewPosition = Progress_Slider . Value ;
156+ player . controls . currentPosition = NewPosition ;
157+ LastProgressSliderThumbDeltaValue = NewPosition ;
158+ LastProgressSliderDeltaEvent . Start ( ) ;
152159 }
153160
154161 private void Progress_Slider_DragCompleted ( object sender , System . Windows . Controls . Primitives . DragCompletedEventArgs e )
155162 {
156163 ProgressSliderChanging = false ;
164+ double NewPosition = Progress_Slider . Value ;
165+ player . controls . currentPosition = NewPosition ;
166+ LastProgressSliderThumbDeltaValue = NewPosition ;
167+ LastProgressSliderDeltaEvent . Stop ( ) ;
168+ }
169+
170+ private void Progress_Slider_DragDelta ( object sender , System . Windows . Controls . Primitives . DragDeltaEventArgs e )
171+ {
172+ //DragDelta runs very often - to prevent lag we throw most of these events out
173+ if ( LastProgressSliderDeltaEvent . ElapsedMilliseconds < 300 )
174+ {
175+ return ;
176+ }
177+
178+ double NewPosition = Progress_Slider . Value ;
179+ if ( Math . Abs ( LastProgressSliderThumbDeltaValue - NewPosition ) > 1 )
180+ {
181+ player . controls . currentPosition = NewPosition ;
182+ LastProgressSliderThumbDeltaValue = NewPosition ;
183+ LastProgressSliderDeltaEvent . Restart ( ) ;
184+ }
157185 }
158186 }
159187}
0 commit comments