mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 18:39:45 +00:00
refine UI and stability
This commit is contained in:
@@ -67,7 +67,7 @@ namespace QuickLook.Plugin.VideoViewer
|
||||
|
||||
var v = (bool) value;
|
||||
|
||||
return v ? Visibility.Visible : Visibility.Hidden;
|
||||
return v ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
@@ -81,11 +81,11 @@ namespace QuickLook.Plugin.VideoViewer
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null)
|
||||
return Visibility.Hidden;
|
||||
return Visibility.Collapsed;
|
||||
|
||||
var v = (bool) value;
|
||||
|
||||
return v ? Visibility.Hidden : Visibility.Visible;
|
||||
return v ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
|
||||
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
|
@@ -28,7 +28,7 @@ namespace QuickLook.Plugin.VideoViewer
|
||||
{
|
||||
public class Plugin : IViewer
|
||||
{
|
||||
private Size _mediaSize;
|
||||
private FFprobe _probe;
|
||||
private ViewerPanel _vp;
|
||||
|
||||
public int Priority => int.MaxValue;
|
||||
@@ -46,24 +46,28 @@ namespace QuickLook.Plugin.VideoViewer
|
||||
if (Directory.Exists(path))
|
||||
return false;
|
||||
|
||||
var blacklist = new[]
|
||||
{
|
||||
".txt", ".jpg", ".bmp"
|
||||
};
|
||||
var blacklist = new[] {".txt", ".jpg", ".bmp", ".tiff"};
|
||||
|
||||
if (blacklist.Contains(Path.GetExtension(path).ToLower()))
|
||||
return false;
|
||||
|
||||
return new FFprobe(path).CanDecode();
|
||||
var probe = new FFprobe(path);
|
||||
|
||||
// check if it is a APNG image
|
||||
if (Path.GetExtension(path).ToLower() == ".png" && probe.GetFormatName().ToLower() != "apng")
|
||||
return false;
|
||||
|
||||
return probe.CanDecode();
|
||||
}
|
||||
|
||||
public void Prepare(string path, ContextObject context)
|
||||
{
|
||||
var def = new Size(450, 450);
|
||||
|
||||
_mediaSize = new FFprobe(path).GetViewSize();
|
||||
_probe = new FFprobe(path);
|
||||
var mediaSize = _probe.GetViewSize();
|
||||
|
||||
var windowSize = _mediaSize == Size.Empty ? def : _mediaSize;
|
||||
var windowSize = mediaSize == Size.Empty ? def : mediaSize;
|
||||
windowSize.Width = Math.Max(def.Width, windowSize.Width);
|
||||
windowSize.Height = Math.Max(def.Height, windowSize.Height);
|
||||
|
||||
@@ -75,14 +79,13 @@ namespace QuickLook.Plugin.VideoViewer
|
||||
_vp = new ViewerPanel(context);
|
||||
|
||||
context.ViewerContent = _vp;
|
||||
|
||||
Debug.WriteLine("ViewerContent done");
|
||||
|
||||
_vp.LoadAndPlay(path);
|
||||
Debug.WriteLine("LoadAndPlay done");
|
||||
|
||||
_vp.mediaElement.MediaOpened += (sender, e) => context.IsBusy = false;
|
||||
|
||||
var info = _mediaSize == Size.Empty ? "Audio" : $"{_mediaSize.Width}×{_mediaSize.Height}";
|
||||
var mediaSize = _probe.GetViewSize();
|
||||
var info = mediaSize == Size.Empty ? "Audio" : $"{mediaSize.Width}×{mediaSize.Height}";
|
||||
|
||||
context.Title =
|
||||
$"{Path.GetFileName(path)} ({info})";
|
||||
@@ -90,6 +93,8 @@ namespace QuickLook.Plugin.VideoViewer
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
_probe = null;
|
||||
|
||||
_vp?.Dispose();
|
||||
_vp = null;
|
||||
}
|
||||
|
@@ -44,8 +44,8 @@
|
||||
</Image.Style>
|
||||
</Image>
|
||||
|
||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Height="100"
|
||||
Visibility="{Binding NaturalDuration.HasTimeSpan, ElementName=mediaElement, Converter={StaticResource BooleanToVisibilityVisibleConverter}}">
|
||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Height="100">
|
||||
<!--Visibility="{Binding NaturalDuration.HasTimeSpan, ElementName=mediaElement, Converter={StaticResource BooleanToVisibilityVisibleConverter}}"-->
|
||||
<Grid.Background>
|
||||
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
|
||||
<GradientStop Offset="0.0" Color="#00000000" />
|
||||
@@ -90,10 +90,10 @@
|
||||
</Grid.Style>
|
||||
|
||||
<Slider Grid.Row="1" x:Name="sliderProgress" Style="{StaticResource PositionSliderStyle}"
|
||||
IsEnabled="{Binding IsOpen, ElementName=mediaElement}"
|
||||
SmallChange="{Binding FrameStepDuration, ElementName=mediaElement,Converter={StaticResource TimeSpanToSecondsConverter}}"
|
||||
LargeChange="{Binding FrameStepDuration, ElementName=mediaElement, Converter={StaticResource TimeSpanToSecondsConverter}}"
|
||||
Maximum="{Binding NaturalDuration, ElementName=mediaElement,Converter={StaticResource TimeSpanToSecondsConverter}}"
|
||||
Visibility="{Binding NaturalDuration.HasTimeSpan, ElementName=mediaElement, Converter={StaticResource BooleanToVisibilityVisibleConverter}}"
|
||||
Value="{Binding Position, ElementName=mediaElement, Converter={StaticResource TimeSpanToSecondsConverter}}" />
|
||||
|
||||
<Grid Grid.Row="2">
|
||||
@@ -103,6 +103,7 @@
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Grid.Column="0" VerticalAlignment="Center"
|
||||
Visibility="{Binding HasAudio, ElementName=mediaElement,Converter={StaticResource BooleanToVisibilityVisibleConverter}}"
|
||||
Orientation="Horizontal" Margin="10,0,0,0">
|
||||
<Grid x:Name="buttonMute" Style="{StaticResource ControlButtonStyle}">
|
||||
<fa:ImageAwesome Height="23" Width="23" Foreground="#FFEFEFEF">
|
||||
@@ -119,7 +120,7 @@
|
||||
</fa:ImageAwesome.Style>
|
||||
</fa:ImageAwesome>
|
||||
</Grid>
|
||||
<Slider Style="{StaticResource CustomSliderStyle}" MaxWidth="75" Maximum="1"
|
||||
<Slider Style="{StaticResource CustomSliderStyle}" Width="75" Maximum="1"
|
||||
Value="{Binding Volume, ElementName=mediaElement}"
|
||||
Visibility="{Binding IsMuted, ElementName=mediaElement, Converter={StaticResource BooleanToVisibilityHiddenConverter}}"
|
||||
BorderThickness="0,0,5,0" />
|
||||
@@ -157,9 +158,11 @@
|
||||
Orientation="Horizontal" Margin="0,0,10,0">
|
||||
<TextBlock FontSize="14" Foreground="#FFEFEFEF"
|
||||
Text="{Binding Position, StringFormat=hh\\:mm\\:ss, ElementName=mediaElement}" />
|
||||
<TextBlock FontSize="14" Text=" / " Foreground="#FFEFEFEF" />
|
||||
<TextBlock FontSize="14" Text=" / " Foreground="#FFEFEFEF"
|
||||
Visibility="{Binding NaturalDuration.HasTimeSpan, ElementName=mediaElement, Converter={StaticResource BooleanToVisibilityVisibleConverter}}" />
|
||||
<TextBlock FontSize="14" Foreground="#FFEFEFEF"
|
||||
Text="{Binding NaturalDuration, StringFormat=hh\\:mm\\:ss, ElementName=mediaElement, Converter={StaticResource DurationToTimeSpanConverter}}" />
|
||||
Text="{Binding NaturalDuration, StringFormat=hh\\:mm\\:ss, ElementName=mediaElement, Converter={StaticResource DurationToTimeSpanConverter}}"
|
||||
Visibility="{Binding NaturalDuration.HasTimeSpan, ElementName=mediaElement, Converter={StaticResource BooleanToVisibilityVisibleConverter}}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
@@ -46,8 +46,8 @@ namespace QuickLook.Plugin.VideoViewer
|
||||
//};
|
||||
buttonMute.MouseLeftButtonUp += (sender, e) => mediaElement.IsMuted = !mediaElement.IsMuted;
|
||||
buttonStop.MouseLeftButtonUp += (sender, e) => mediaElement.Stop();
|
||||
buttonBackward.MouseLeftButtonUp += (sender, e) => SeekBackward();
|
||||
buttonForward.MouseLeftButtonUp += (sender, e) => SeekForward();
|
||||
buttonBackward.MouseLeftButtonUp += (sender, e) => Seek(TimeSpan.FromSeconds(-10));
|
||||
buttonForward.MouseLeftButtonUp += (sender, e) => Seek(TimeSpan.FromSeconds(10));
|
||||
|
||||
sliderProgress.PreviewMouseDown += (sender, e) =>
|
||||
{
|
||||
@@ -60,52 +60,44 @@ namespace QuickLook.Plugin.VideoViewer
|
||||
};
|
||||
|
||||
mediaElement.MediaFailed += ShowErrorNotification;
|
||||
mediaElement.MediaEnded += (s, e) =>
|
||||
/*mediaElement.MediaEnded += (s, e) =>
|
||||
{
|
||||
if (!mediaElement.NaturalDuration.HasTimeSpan)
|
||||
{
|
||||
mediaElement.Stop();
|
||||
mediaElement.Play();
|
||||
}
|
||||
};
|
||||
if (mediaElement.IsOpen)
|
||||
if (!mediaElement.NaturalDuration.HasTimeSpan)
|
||||
{
|
||||
mediaElement.Stop();
|
||||
mediaElement.Play();
|
||||
}
|
||||
};*/
|
||||
|
||||
PreviewMouseWheel += (sender, e) => ChangeVolume((double) e.Delta / 120 / 50);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
mediaElement?.Stop();
|
||||
mediaElement?.Dispose();
|
||||
try
|
||||
{
|
||||
mediaElement?.Stop();
|
||||
mediaElement?.Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine(e);
|
||||
}
|
||||
mediaElement = null;
|
||||
Debug.WriteLine("dispose done");
|
||||
}
|
||||
|
||||
private void ResumePlaying()
|
||||
private void ChangeVolume(double delta)
|
||||
{
|
||||
_wasPlaying = mediaElement.IsPlaying;
|
||||
mediaElement.Volume += delta;
|
||||
}
|
||||
|
||||
private void SeekBackward()
|
||||
private void Seek(TimeSpan delta)
|
||||
{
|
||||
_wasPlaying = mediaElement.IsPlaying;
|
||||
mediaElement.Pause();
|
||||
|
||||
var pos = mediaElement.Position;
|
||||
var delta = TimeSpan.FromSeconds(15);
|
||||
|
||||
mediaElement.Position = pos < pos - delta ? TimeSpan.Zero : pos - delta;
|
||||
|
||||
if (_wasPlaying) mediaElement.Play();
|
||||
}
|
||||
|
||||
private void SeekForward()
|
||||
{
|
||||
_wasPlaying = mediaElement.IsPlaying;
|
||||
mediaElement.Pause();
|
||||
|
||||
var pos = mediaElement.Position;
|
||||
var len = mediaElement.NaturalDuration.TimeSpan;
|
||||
var delta = TimeSpan.FromSeconds(15);
|
||||
|
||||
mediaElement.Position = pos + delta > len ? len : pos + delta;
|
||||
mediaElement.Position = mediaElement.Position + delta;
|
||||
|
||||
if (_wasPlaying) mediaElement.Play();
|
||||
}
|
||||
@@ -113,9 +105,15 @@ namespace QuickLook.Plugin.VideoViewer
|
||||
private void TogglePlayPause(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (mediaElement.IsPlaying)
|
||||
{
|
||||
mediaElement.Pause();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mediaElement.HasMediaEnded)
|
||||
mediaElement.Stop();
|
||||
mediaElement.Play();
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerNonUserCode]
|
||||
@@ -133,7 +131,7 @@ namespace QuickLook.Plugin.VideoViewer
|
||||
public void LoadAndPlay(string path)
|
||||
{
|
||||
mediaElement.Source = new Uri(path);
|
||||
mediaElement.MediaOpened += (sender, e) => mediaElement.IsMuted = true;
|
||||
mediaElement.MediaOpened += (sender, e) => mediaElement.Volume = 0.2;
|
||||
}
|
||||
|
||||
~ViewerPanel()
|
||||
|
Binary file not shown.
BIN
QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ffme/ffme.pdb
Normal file
BIN
QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ffme/ffme.pdb
Normal file
Binary file not shown.
Binary file not shown.
BIN
QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ffme/ffmpeg.pdb
Normal file
BIN
QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ffme/ffmpeg.pdb
Normal file
Binary file not shown.
Reference in New Issue
Block a user