From 39feab58a3fe2776d84ac22f8a4a44a07353b407 Mon Sep 17 00:00:00 2001 From: ema Date: Tue, 14 Apr 2026 23:25:58 +0800 Subject: [PATCH] Revert attempt to ARM64 VideoViewer --- .../Converters.cs | 44 ---- .../QuickLook.Plugin.VideoViewer/Plugin.cs | 10 +- .../ViewerPanel.GlassLayer.cs | 5 +- .../ViewerPanel.xaml | 41 --- .../ViewerPanel.xaml.cs | 234 +++--------------- 5 files changed, 45 insertions(+), 289 deletions(-) diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Converters.cs b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Converters.cs index 0269071..62f4f44 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Converters.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Converters.cs @@ -88,47 +88,3 @@ public sealed class CoverArtConverter : IValueConverter throw new NotImplementedException(); } } - -public sealed class TimeToLongConverter : DependencyObject, IValueConverter -{ - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value is long v) - return TimeSpan.FromTicks((long)v); - else - return TimeSpan.FromTicks(0L); - } - - object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value is TimeSpan v) - return ((TimeSpan)v).Ticks; - else - return 0L; - - } -} - -public sealed class TimeToShortStringConverter : DependencyObject, IValueConverter -{ - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value == null) - return "00:00"; - - var v = (TimeSpan)value; - - var s = string.Empty; - if (v.Hours > 0) - s += $"{v.Hours:D2}:"; - - s += $"{v.Minutes:D2}:{v.Seconds:D2}"; - - return s; - } - - object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } -} diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Plugin.cs index 3c12bce..cded582 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Plugin.cs @@ -22,7 +22,6 @@ using QuickLook.Common.Plugin; using System; using System.IO; using System.Reflection; -using System.Runtime.InteropServices; using System.Windows; namespace QuickLook.Plugin.VideoViewer; @@ -32,7 +31,6 @@ public sealed class Plugin : IViewer private static MediaInfoLib _mediaInfo; private ViewerPanel _vp; - private static readonly bool isArm64 = RuntimeInformation.ProcessArchitecture == Architecture.Arm64; public int Priority => -3; @@ -40,7 +38,7 @@ public sealed class Plugin : IViewer { _mediaInfo = new MediaInfoLib(Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), - isArm64 ? @"MediaInfo-arm64\" : Environment.Is64BitProcess ? @"MediaInfo-x64\" : @"MediaInfo-x86\")); + Environment.Is64BitProcess ? @"MediaInfo-x64\" : @"MediaInfo-x86\")); _mediaInfo.Option("Cover_Data", "base64"); } @@ -130,10 +128,8 @@ public sealed class Plugin : IViewer context.ViewerContent = _vp; context.Title = $"{Path.GetFileName(path)}"; - if (isArm64) - _vp.LoadAndPlayWPF(path, _mediaInfo); - else - _vp.LoadAndPlay(path, _mediaInfo); + + _vp.LoadAndPlay(path, _mediaInfo); } public void Cleanup() diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.GlassLayer.cs b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.GlassLayer.cs index b202e4b..318bd35 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.GlassLayer.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.GlassLayer.cs @@ -31,7 +31,6 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan /// /// Load and insert the GlassLayer control to the videoControlContainer. /// - private partial void LoadAndInsertGlassLayer() { // Replace XAML with C# dynamic construction @@ -116,7 +115,7 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan var blurredElementSetter = new Setter((DependencyProperty)blurredElementProperty, new Binding() { - ElementName = isArm64 ? "mediaElementWPF" : "mediaElement" + ElementName = "mediaElement" }); style.Setters.Add(blurredElementSetter); @@ -132,7 +131,7 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan var dataTriggerSetter = new Setter((DependencyProperty)blurredElementProperty, new Binding() { - ElementName = isArm64 ? "mediaElementWPF" : "mediaElement" + ElementName = "mediaElement" }); dataTrigger.Setters.Add(dataTriggerSetter); diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml index 208dcc9..ad404a2 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml @@ -13,8 +13,6 @@ - - @@ -24,7 +22,6 @@ - @@ -207,7 +204,6 @@ - - volumeSliderLayer.Visibility = Visibility.Visible; - volumeSliderLayer.MouseDown += (_, _) => volumeSliderLayer.Visibility = Visibility.Collapsed; - - - PreviewMouseWheel += (_, e) => ChangeVolume(e.Delta / 120d * 0.04d); - } - - private void InitializeDefault() - { - sliderProgress.Visibility = Visibility.Visible; - buttonTime.Visibility = Visibility.Visible; - - mediaElement.MediaUriPlayer.LAVFilterDirectory = (IntPtr.Size == 8 ? @"LAVFilters-x64\" : @"LAVFilters-x86\"); mediaElement.MediaUriPlayer.PlayerStateChanged += PlayerStateChanged; mediaElement.MediaOpened += MediaOpened; mediaElement.MediaEnded += MediaEnded; mediaElement.MediaFailed += MediaFailed; + ShouldLoop = SettingHelper.Get("ShouldLoop", false, "QuickLook.Plugin.VideoViewer"); + + buttonPlayPause.Click += TogglePlayPause; + buttonLoop.Click += ToggleShouldLoop; buttonTime.Click += (_, _) => buttonTime.Tag = (string)buttonTime.Tag == "Time" ? "Length" : "Time"; + buttonMute.Click += (_, _) => volumeSliderLayer.Visibility = Visibility.Visible; + volumeSliderLayer.MouseDown += (_, _) => volumeSliderLayer.Visibility = Visibility.Collapsed; + sliderProgress.PreviewMouseDown += (_, e) => { _wasPlaying = mediaElement.IsPlaying; @@ -116,66 +94,8 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan { if (_wasPlaying) mediaElement.Play(); }; - } - private void InitializeArm64() - { - sliderProgressWPF.Visibility = Visibility.Visible; - buttonTimeWPF.Visibility = Visibility.Visible; - - mediaElementWPF.MediaOpened += MediaOpened; - mediaElementWPF.MediaEnded += MediaEnded; - - buttonTimeWPF.Click += (_, _) => buttonTimeWPF.Tag = (string)buttonTimeWPF.Tag == "Time" ? "Length" : "Time"; - - - timer = new DispatcherTimer - { - Interval = TimeSpan.FromSeconds(1) - }; - timer.Tick += Seek_Timer; - timer.Start(); - - buttonTimeWPF.Click += (_, _) => buttonTime.Tag = (string)buttonTime.Tag == "Time" ? "Length" : "Time"; - - sliderProgressWPF.PreviewMouseDown += (_, e) => - { - _wasPlaying = IsPlaying; - mediaElementWPF.Pause(); - }; - sliderProgressWPF.PreviewMouseUp += (_, _) => - { - if (_wasPlaying) mediaElementWPF.Play(); - }; - - IsSeeked = false; - } - - private void Seek_Timer(object sender, EventArgs e) - { - if ((mediaElementWPF.Source != null) && (mediaElementWPF.NaturalDuration.HasTimeSpan) && (!IsSeeked)) - { - sliderProgressWPF.Minimum = 0; - sliderProgressWPF.Maximum = mediaElementWPF.NaturalDuration.TimeSpan.TotalSeconds; - sliderProgressWPF.Value = mediaElementWPF.Position.TotalSeconds; - - } - } - private void Seek_Drag_Started(object sender, DragStartedEventArgs e) - { - IsSeeked = true; - } - private void Seek_Drag_Completed(object sender, DragCompletedEventArgs e) - { - IsSeeked = false; - mediaElementWPF.Position = TimeSpan.FromSeconds(sliderProgressWPF.Value); - } - private void Seek_Value_Changed(object sender, RoutedPropertyChangedEventArgs e) - { - if ((string)buttonTimeWPF.Tag == "Time") - textProgress.Text = TimeSpan.FromSeconds(sliderProgressWPF.Value).ToString(@"hh\:mm\:ss"); - else - textProgress.Text = TimeSpan.FromSeconds(sliderProgressWPF.Maximum).ToString(@"hh\:mm\:ss"); + PreviewMouseWheel += (_, e) => ChangeVolume(e.Delta / 120d * 0.04d); } private partial void LoadAndInsertGlassLayer(); @@ -210,12 +130,6 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan if (value == _shouldLoop) return; _shouldLoop = value; OnPropertyChanged(); - if (!IsPlaying) - { - IsPlaying = true; - - if (isArm64) mediaElementWPF.Play(); else mediaElement.Play(); - } } } @@ -239,18 +153,15 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan try { - if (timer!=null) - timer.Stop(); mediaElement?.Close(); - mediaElementWPF?.Close(); Task.Run(() => { mediaElement?.MediaUriPlayer.Dispose(); mediaElement = null; - mediaElementWPF = null; }); - } catch (Exception e) + } + catch (Exception e) { Debug.WriteLine(e); } @@ -274,21 +185,10 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan private void MediaOpened(object o, RoutedEventArgs args) { - if (isArm64) - { - if (mediaElementWPF == null) - return; + if (mediaElement == null) + return; - HasVideo = mediaElementWPF.HasVideo; - - } else - { - if (mediaElement == null) - return; - - HasVideo = mediaElement.HasVideo; - - } + HasVideo = mediaElement.HasVideo; _context.IsBusy = false; } @@ -309,42 +209,21 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan private void MediaEnded(object sender, RoutedEventArgs e) { - if (isArm64) + if (mediaElement == null) + return; + + mediaElement.MediaPosition = 0L; + if (ShouldLoop) { - if (mediaElementWPF == null) - return; + IsPlaying = true; - mediaElementWPF.Position = new TimeSpan(0L); - if (ShouldLoop) - { - IsPlaying = true; - - mediaElementWPF.Play(); - } else - { - IsPlaying = false; - - mediaElementWPF.Pause(); - } - - } else + mediaElement.Play(); + } + else { - if (mediaElement == null) - return; - - mediaElement.MediaPosition = 0L; - if (ShouldLoop) - { - IsPlaying = true; - - mediaElement.Play(); - } else - { - IsPlaying = false; - - mediaElement.Pause(); - } + IsPlaying = false; + mediaElement.Pause(); } } @@ -406,7 +285,8 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan var coverData = info.Get(StreamKind.General, 0, "Cover_Data"); var coverBytes = CoverDataExtractor.Extract(coverData); CoverArt = CoverDataExtractor.Extract(coverBytes); - } catch (Exception e) + } + catch (Exception e) { Debug.WriteLine(e); metaTitle.Text = Path.GetFileName(path); @@ -461,9 +341,10 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan { if (_lyricLines != null && _lyricLines.Length != 0) { - var lyric = LrcHelper.GetNearestLrc(_lyricLines, new TimeSpan(isArm64 ? mediaElementWPF.Position.Ticks : mediaElement.MediaPosition)); + var lyric = LrcHelper.GetNearestLrc(_lyricLines, new TimeSpan(mediaElement.MediaPosition)); metaLyric.Text = lyric?.LrcText?.Trim(); - } else + } + else { metaLyric.Text = null; metaLyric.Visibility = Visibility.Collapsed; @@ -472,7 +353,8 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan _lyricTimer.Start(); metaLyric.Visibility = Visibility.Visible; - } else + } + else { metaLyric.Visibility = Visibility.Collapsed; } @@ -480,10 +362,10 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan public double LinearVolume { - get => (isArm64 ? mediaElementWPF.Volume : mediaElement.Volume); + get => mediaElement.Volume; set { - if (isArm64) mediaElementWPF.Volume = value; else mediaElement.Volume = value; + mediaElement.Volume = value; OnPropertyChanged(); } } @@ -495,53 +377,17 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan private void TogglePlayPause(object sender, EventArgs e) { - if (isArm64) - { - if (IsPlaying) - { - IsPlaying = false; - mediaElementWPF.Pause(); - } else - { - IsPlaying = true; - mediaElementWPF.Play(); - } - } else - { - if (mediaElement.IsPlaying) - mediaElement.Pause(); - else - mediaElement.Play(); - } + if (mediaElement.IsPlaying) + mediaElement.Pause(); + else + mediaElement.Play(); } private void ToggleShouldLoop(object sender, EventArgs e) { ShouldLoop = !ShouldLoop; } - public void LoadAndPlayWPF(string path, MediaInfoLib info) - { - // Detect whether it is other playback formats - if (!HasVideo) - { - string audioCodec = info?.Get(StreamKind.Audio, 0, "Format"); - if (audioCodec?.Equals("MIDI", StringComparison.OrdinalIgnoreCase) ?? false) - { - _midiPlayer = new MidiPlayer(this, _context); - _midiPlayer.LoadAndPlay(path); - return; // Midi player will handle the playback at all - } - } - - UpdateMeta(path, info); - - mediaElementWPF.Source = new Uri(path); - // old plugin use an int-typed "Volume" config key ranged from 0 to 100. Let's use a new one here. - LinearVolume = SettingHelper.Get("VolumeDouble", 1d, "QuickLook.Plugin.VideoViewer"); - - mediaElementWPF.Play(); - } public void LoadAndPlay(string path, MediaInfoLib info) { // Detect whether it is other playback formats