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>
</Button.Style>
</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.Style>
<Style TargetType="Button" BasedOn="{StaticResource ControlButtonStyle}">

View File

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