add seek buttons

This commit is contained in:
Paddy Xu
2017-07-29 11:49:48 +03:00
parent f03719af81
commit a5df20851d
2 changed files with 30 additions and 1 deletions

View File

@@ -7,6 +7,7 @@
xmlns:local="clr-namespace:QuickLook.Plugin.VideoViewer" xmlns:local="clr-namespace:QuickLook.Plugin.VideoViewer"
xmlns:ffmpeg="clr-namespace:Unosquare.FFmpegMediaElement;assembly=Unosquare.FFmpegMediaElement" xmlns:ffmpeg="clr-namespace:Unosquare.FFmpegMediaElement;assembly=Unosquare.FFmpegMediaElement"
mc:Ignorable="d" mc:Ignorable="d"
Background="#B2454545"
d:DesignHeight="449.167" d:DesignWidth="767"> d:DesignHeight="449.167" d:DesignWidth="767">
<Grid> <Grid>
<Grid.Resources> <Grid.Resources>
@@ -94,6 +95,10 @@
Visibility="{Binding IsMuted, ElementName=mediaElement, Converter={StaticResource BooleanToVisibilityHiddenConverter}}" /> Visibility="{Binding IsMuted, ElementName=mediaElement, Converter={StaticResource BooleanToVisibilityHiddenConverter}}" />
</StackPanel> </StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center"> <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center">
<Grid x:Name="buttonBackward" Style="{StaticResource ControlButtonStyle}">
<fa:ImageAwesome Icon="Backward" Height="27" Width="27" Foreground="#FFEFEFEF" />
</Grid>
<Grid Width="7" />
<Grid x:Name="buttonPlayPause" Style="{StaticResource ControlButtonStyle}"> <Grid x:Name="buttonPlayPause" Style="{StaticResource ControlButtonStyle}">
<fa:ImageAwesome Height="30" Width="30" Foreground="#FFEFEFEF"> <fa:ImageAwesome Height="30" Width="30" Foreground="#FFEFEFEF">
<fa:ImageAwesome.Style> <fa:ImageAwesome.Style>
@@ -109,10 +114,14 @@
</fa:ImageAwesome.Style> </fa:ImageAwesome.Style>
</fa:ImageAwesome> </fa:ImageAwesome>
</Grid> </Grid>
<Grid Width="15" /> <Grid Width="7" />
<Grid x:Name="buttonStop" Style="{StaticResource ControlButtonStyle}"> <Grid x:Name="buttonStop" Style="{StaticResource ControlButtonStyle}">
<fa:ImageAwesome Icon="Stop" Height="27" Width="27" Foreground="#FFEFEFEF" /> <fa:ImageAwesome Icon="Stop" Height="27" Width="27" Foreground="#FFEFEFEF" />
</Grid> </Grid>
<Grid Width="7" />
<Grid x:Name="buttonForward" Style="{StaticResource ControlButtonStyle}">
<fa:ImageAwesome Icon="Forward" Height="27" Width="27" Foreground="#FFEFEFEF" />
</Grid>
</StackPanel> </StackPanel>
<StackPanel Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center" <StackPanel Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center"
Orientation="Horizontal" Margin="0,0,20,0"> Orientation="Horizontal" Margin="0,0,20,0">

View File

@@ -44,6 +44,8 @@ namespace QuickLook.Plugin.VideoViewer
//}; //};
buttonMute.MouseLeftButtonUp += (sender, e) => mediaElement.IsMuted = !mediaElement.IsMuted; buttonMute.MouseLeftButtonUp += (sender, e) => mediaElement.IsMuted = !mediaElement.IsMuted;
buttonStop.MouseLeftButtonUp += (sender, e) => mediaElement.Stop(); buttonStop.MouseLeftButtonUp += (sender, e) => mediaElement.Stop();
buttonBackward.MouseLeftButtonUp += (sender, e) => SeekBackward();
buttonForward.MouseLeftButtonUp += (sender, e) => SeekForward();
mediaElement.MediaErrored += ShowErrorNotification; mediaElement.MediaErrored += ShowErrorNotification;
mediaElement.MediaFailed += ShowErrorNotification; mediaElement.MediaFailed += ShowErrorNotification;
@@ -55,6 +57,24 @@ namespace QuickLook.Plugin.VideoViewer
mediaElement = null; mediaElement = null;
} }
private void SeekBackward()
{
var pos = Convert.ToDouble(mediaElement.Position);
var len = mediaElement.NaturalDuration;
var delta = TimeSpan.FromSeconds(15).TotalSeconds;
mediaElement.Position = Convert.ToDecimal(pos - delta < 0 ? 0 : pos - delta);
}
private void SeekForward()
{
var pos = Convert.ToDouble(mediaElement.Position);
var len = mediaElement.NaturalDuration;
var delta = TimeSpan.FromSeconds(15).TotalSeconds;
mediaElement.Position = Convert.ToDecimal(pos + delta > len ? len : pos + delta);
}
private void TogglePlayPause(object sender, MouseButtonEventArgs e) private void TogglePlayPause(object sender, MouseButtonEventArgs e)
{ {
if (mediaElement.IsPlaying) if (mediaElement.IsPlaying)