11using System ;
2+ using System . Diagnostics ;
23using System . Threading ;
34using System . Windows ;
45using System . Windows . Threading ;
@@ -16,7 +17,10 @@ public partial class MainWindow : Window
1617
1718 double volume ;
1819 double prevVolume ;
19- string path ;
20+ bool ProgressSliderChanging = false ;
21+ double LastProgressSliderThumbDeltaValue = 0 ;
22+ Stopwatch LastProgressSliderDeltaEvent = new Stopwatch ( ) ;
23+ string path ;
2024 Thread LoopingThread ;
2125
2226
@@ -66,7 +70,7 @@ private void Looper()
6670
6771 this . Dispatcher . Invoke ( ( ) =>
6872 {
69- if ( player . currentMedia . duration > 1 && player . controls . currentPosition > 1 )
73+ if ( player . currentMedia . duration > 1 && player . controls . currentPosition > 1 && ! ProgressSliderChanging )
7074 {
7175
7276 UpdateSongPosition ( ) ;
@@ -144,7 +148,42 @@ private void Close(object sender, System.ComponentModel.CancelEventArgs e)
144148 {
145149 LoopingThread . Abort ( ) ;
146150 }
147- }
151+
152+ private void Progress_Slider_DragStarted ( object sender , System . Windows . Controls . Primitives . DragStartedEventArgs e )
153+ {
154+ ProgressSliderChanging = true ;
155+ double NewPosition = Progress_Slider . Value ;
156+ player . controls . currentPosition = NewPosition ;
157+ LastProgressSliderThumbDeltaValue = NewPosition ;
158+ LastProgressSliderDeltaEvent . Start ( ) ;
159+ }
160+
161+ private void Progress_Slider_DragCompleted ( object sender , System . Windows . Controls . Primitives . DragCompletedEventArgs e )
162+ {
163+ 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+ }
185+ }
186+ }
148187}
149188
150189
0 commit comments