Add option to loop videos

Ref: #496
This commit is contained in:
Jethro Alter
2019-09-29 17:19:25 +02:00
committed by Paddy Xu
parent 6f0e7a6a2b
commit 401976e280
2 changed files with 49 additions and 3 deletions

View File

@@ -145,6 +145,19 @@
</Style> </Style>
</Button.Style> </Button.Style>
</Button> </Button>
<Button x:Name="buttonLoop" DockPanel.Dock="Left">
<Button.Style>
<Style TargetType="Button" BasedOn="{StaticResource ControlButtonStyle}">
<Setter Property="Content" Value="&#xE72C;" />
<Style.Triggers>
<DataTrigger Binding="{Binding ShouldLoop, ElementName=viewerPanel}"
Value="True">
<Setter Property="Content" Value="&#xE777;" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<Button x:Name="buttonMute" DockPanel.Dock="Right"> <Button x:Name="buttonMute" DockPanel.Dock="Right">
<Button.Style> <Button.Style>
<Style TargetType="Button" BasedOn="{StaticResource ControlButtonStyle}"> <Style TargetType="Button" BasedOn="{StaticResource ControlButtonStyle}">

View File

@@ -48,6 +48,7 @@ namespace QuickLook.Plugin.VideoViewer
private bool _hasVideo; private bool _hasVideo;
private bool _isPlaying; private bool _isPlaying;
private bool _wasPlaying; private bool _wasPlaying;
private bool _shouldLoop;
public ViewerPanel(ContextObject context) public ViewerPanel(ContextObject context)
{ {
@@ -70,6 +71,7 @@ namespace QuickLook.Plugin.VideoViewer
mediaElement.MediaFailed += MediaFailed; mediaElement.MediaFailed += MediaFailed;
buttonPlayPause.Click += TogglePlayPause; buttonPlayPause.Click += TogglePlayPause;
buttonLoop.Click += ToggleShouldLoop;
buttonTime.Click += (sender, e) => buttonTime.Tag = (string) buttonTime.Tag == "Time" ? "Length" : "Time"; buttonTime.Click += (sender, e) => buttonTime.Tag = (string) buttonTime.Tag == "Time" ? "Length" : "Time";
buttonMute.Click += (sender, e) => volumeSliderLayer.Visibility = Visibility.Visible; buttonMute.Click += (sender, e) => volumeSliderLayer.Visibility = Visibility.Visible;
volumeSliderLayer.MouseDown += (sender, e) => volumeSliderLayer.Visibility = Visibility.Collapsed; volumeSliderLayer.MouseDown += (sender, e) => volumeSliderLayer.Visibility = Visibility.Collapsed;
@@ -109,6 +111,23 @@ namespace QuickLook.Plugin.VideoViewer
} }
} }
public bool ShouldLoop
{
get => _shouldLoop;
private set
{
if (value == _shouldLoop) return;
_shouldLoop = value;
OnPropertyChanged();
if (!IsPlaying)
{
IsPlaying = true;
mediaElement.Play();
}
}
}
public BitmapSource CoverArt public BitmapSource CoverArt
{ {
get => _coverArt; get => _coverArt;
@@ -169,10 +188,19 @@ namespace QuickLook.Plugin.VideoViewer
if (mediaElement == null) if (mediaElement == null)
return; return;
IsPlaying = false;
mediaElement.MediaPosition = 0; mediaElement.MediaPosition = 0;
mediaElement.Pause(); if (ShouldLoop)
{
IsPlaying = true;
mediaElement.Play();
}
else
{
IsPlaying = false;
mediaElement.Pause();
}
} }
private void ShowViedoControlContainer(object sender, MouseEventArgs e) private void ShowViedoControlContainer(object sender, MouseEventArgs e)
@@ -266,6 +294,11 @@ namespace QuickLook.Plugin.VideoViewer
mediaElement.Play(); mediaElement.Play();
} }
private void ToggleShouldLoop(object sender, EventArgs e)
{
ShouldLoop = !ShouldLoop;
}
public void LoadAndPlay(string path, MediaInfo.MediaInfo info) public void LoadAndPlay(string path, MediaInfo.MediaInfo info)
{ {
UpdateMeta(path, info); UpdateMeta(path, info);