Skip to content

Commit 7197c1e

Browse files
authored
Merge pull request #6 from andrew-mi/master
Fixed #2
2 parents de41eae + c93fc8c commit 7197c1e

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

CSediaPlayer/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<Button x:Name="pause" Content="Pause" HorizontalAlignment="Left" Height="51" Margin="523,0,0,315" VerticalAlignment="Bottom" Width="146" Click="Pause"/>
1313
<Button x:Name="stop" Content="Stop" HorizontalAlignment="Right" Height="51" Margin="0,0,574,315" VerticalAlignment="Bottom" Width="136" Click="Stop"/>
1414
<Button x:Name="select" Content="Song Select" HorizontalAlignment="Right" Height="51" Margin="0,0,422,315" VerticalAlignment="Bottom" Width="147" Click="Select"/>
15-
<Slider x:Name="Progress_Slider" Height="30" Margin="0,275,123,0" VerticalAlignment="Top" Value="0.1" HorizontalAlignment="Right" Width="587"/>
15+
<Slider x:Name="Progress_Slider" Height="30" Margin="0,275,123,0" VerticalAlignment="Top" Value="0.1" HorizontalAlignment="Right" Width="587" Thumb.DragStarted="Progress_Slider_DragStarted" Thumb.DragCompleted="Progress_Slider_DragCompleted" Thumb.DragDelta="Progress_Slider_DragDelta"/>
1616
<TextBlock x:Name="Current_Playing" HorizontalAlignment="Right" Height="56" Margin="0,173,10,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="601"><Run Text="Now Playing"/><LineBreak/><Run/></TextBlock>
1717
<TextBlock x:Name="Current_Time" HorizontalAlignment="Left" Margin="55,275,0,0" TextWrapping="Wrap" Text="0:00" VerticalAlignment="Top"/>
1818
<TextBlock x:Name="Max_Time" HorizontalAlignment="Right" Margin="0,275,96,0" TextWrapping="Wrap" Text="0:00" VerticalAlignment="Top"/>

CSediaPlayer/MainWindow.xaml.cs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Threading;
34
using System.Windows;
45
using 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

Comments
 (0)