Skip to content

Commit 01f348f

Browse files
committed
Smooth Position Slider
1 parent de41eae commit 01f348f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
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"/>
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: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public partial class MainWindow : Window
1616

1717
double volume;
1818
double prevVolume;
19+
bool ProgressSliderChanging = false;
1920
string path;
2021
Thread LoopingThread;
2122

@@ -66,7 +67,7 @@ private void Looper()
6667

6768
this.Dispatcher.Invoke(() =>
6869
{
69-
if (player.currentMedia.duration > 1 && player.controls.currentPosition > 1)
70+
if (player.currentMedia.duration > 1 && player.controls.currentPosition > 1 && !ProgressSliderChanging)
7071
{
7172

7273
UpdateSongPosition();
@@ -144,7 +145,17 @@ private void Close(object sender, System.ComponentModel.CancelEventArgs e)
144145
{
145146
LoopingThread.Abort();
146147
}
147-
}
148+
149+
private void Progress_Slider_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
150+
{
151+
ProgressSliderChanging = true;
152+
}
153+
154+
private void Progress_Slider_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
155+
{
156+
ProgressSliderChanging = false;
157+
}
158+
}
148159
}
149160

150161

0 commit comments

Comments
 (0)