From 6e4f62b9aaa378dc75716565453d420a891873ba Mon Sep 17 00:00:00 2001 From: SplitGemini <764402868@qq.com> Date: Thu, 30 Apr 2020 13:53:24 +0800 Subject: [PATCH] add lyric line in VideoViewer --- .../QuickLook.Installer.wixproj | 3 +- .../QuickLook.Plugin.ImageViewer/Plugin.cs | 4 +- .../Plugin.cs | 2 +- .../Lyric/LrcLine.cs | 18 +------- .../Lyric/LrcManager.cs | 3 +- .../QuickLook.Plugin.VideoViewer/Plugin.cs | 13 +++--- .../QuickLook.Plugin.VideoViewer.csproj | 2 + .../ViewerPanel.xaml | 2 + .../ViewerPanel.xaml.cs | 44 +++++++++++++++---- QuickLook/DesktopWatcher.cs | 3 +- README.md | 8 ++-- 11 files changed, 61 insertions(+), 41 deletions(-) diff --git a/QuickLook.Installer/QuickLook.Installer.wixproj b/QuickLook.Installer/QuickLook.Installer.wixproj index 870902559..aff06c1ed 100644 --- a/QuickLook.Installer/QuickLook.Installer.wixproj +++ b/QuickLook.Installer/QuickLook.Installer.wixproj @@ -72,8 +72,7 @@ powershell -file "$(SolutionDir)Scripts\pack-zip.ps1" rmdir /S /Q "$(SolutionDir)Build\Package" - powershell -file "$(SolutionDir)Scripts\rename-msi.ps1" -rmdir /S /Q "$(SolutionDir)Build\Package" + rmdir /S /Q "$(SolutionDir)Build\Package" mkdir "$(SolutionDir)Build\Package" robocopy "$(SolutionDir)Build\$(Configuration)" "$(SolutionDir)Build\Package" %2a.%2a /e /njh /njs /ndl /nfl /nc /ns /np /xf %2a.pdb /xf %2a.obj /xf %2a.ipdb /xf %2a.iobj /xf %2a.exp /xf %2a.lib /xf %2a.ilk /xf %2a.xml "$(WIX)bin\heat" dir "$(SolutionDir)Build\Package" -dr INSTALLFOLDER -cg QuickLookComponents -gg -g1 -sf -srd -sreg -var "var.PackageDir" -out "$(ProjectDir)C_QuickLookComponents.wxs" diff --git a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs index 5a7cef18d..3a947817c 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs @@ -30,10 +30,10 @@ public class Plugin : IViewer { private static readonly string[] Formats = { - // camera raw ,add dds,tga ;add by gh + // camera raw ,add dds - add by gh ".ari", ".arw", ".bay", ".crw", ".cr2", ".cap", ".dcs", ".dcr", ".dng", ".drf", ".eip", ".erf", ".fff", ".iiq", ".k25", ".kdc", ".mdc", ".mef", ".mos", ".mrw", ".nef", ".nrw", ".obm", ".orf", ".pef", ".ptx", - ".pxn", ".r3d", ".raf", ".raw", ".rwl", ".rw2", ".rwz", ".sr2", ".srf", ".srw", ".x3f",".dds",".tga", + ".pxn", ".r3d", ".raf", ".raw", ".rwl", ".rw2", ".rwz", ".sr2", ".srf", ".srw", ".x3f", ".dds", // normal ".bmp",".heic", ".heif", ".ico", ".icon", ".jpg", ".jpeg", ".psd", ".wdp", ".tif", ".tiff", ".tga", ".webp", ".pbm", ".pgm", ".ppm", ".pnm", diff --git a/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer-Native/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer-Native/Plugin.cs index 35cd14759..d3399ae7e 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer-Native/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer-Native/Plugin.cs @@ -58,7 +58,7 @@ public void Prepare(string path, ContextObject context) //comment by gh - I need larger size //context.SetPreferredSizeFit(new Size {Width = 800, Height = 800}, 0.8); //----------------// - context.SetPreferredSizeFit(new Size { Width = 1200, Height = 800 }, 0.8); + context.SetPreferredSizeFit(new Size { Width = 1200, Height = 800 }, 0.9); } public void View(string path, ContextObject context) diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Lyric/LrcLine.cs b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Lyric/LrcLine.cs index 44d2ee135..e074bb3be 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Lyric/LrcLine.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Lyric/LrcLine.cs @@ -1,4 +1,5 @@ -using System; +/* create by gh */ +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -32,22 +33,7 @@ public LrcLine(TimeSpan? time, string text) } LrcText = text; } - public LrcLine(TimeSpan? time) - : this(time, string.Empty) - { - } - public LrcLine(LrcLine lrcLine) - : this(lrcLine.LrcTime, lrcLine.LrcText) - { - //LrcTime = lrcLine.LrcTime; - //LrcText = lrcLine.LrcText; - } - public LrcLine(string line) - : this(Parse(line)) - { - - } public LrcLine() { LrcTime = null; diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Lyric/LrcManager.cs b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Lyric/LrcManager.cs index 273948f6b..1c2732da9 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Lyric/LrcManager.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Lyric/LrcManager.cs @@ -1,4 +1,5 @@ -using System; +/* create by gh */ +using System; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Plugin.cs index 7f9901985..53349dd04 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Plugin.cs @@ -29,7 +29,7 @@ public class Plugin : IViewer { private static readonly string[] Formats = { - // video - add rmvb + // video - add rmvb by gh ".3g2", ".3gp", ".3gp2", ".3gpp", ".amv", ".asf", ".asf", ".avi", ".flv", ".mts", ".m2ts", ".m4v", ".mkv", ".mov", ".mp4", ".mp4v", ".mpeg", ".mpg", ".ogv", ".qt", ".tp", ".ts", ".vob", ".webm", ".wmv",".rmvb", // audio @@ -61,7 +61,7 @@ public void Prepare(string path, ContextObject context) try { - //editby gh + //edit by gh _mediaInfo = new MediaInfo.MediaInfo(Assembly.GetExecutingAssembly().Location); //_mediaInfo = new MediaInfo.MediaInfo(); //_mediaInfo = new MediaInfo.MediaInfo(Path.Combine( @@ -69,9 +69,9 @@ public void Prepare(string path, ContextObject context) //Environment.Is64BitProcess ? "MediaInfo-x64\\" : "MediaInfo-x86\\")); //----------// - //-----comment by gh--- + //comment by gh //_mediaInfo.Option("Cover_Data", "base64"); - //--------------------- + //---------------------// _mediaInfo.Open(path); @@ -100,7 +100,10 @@ public void Prepare(string path, ContextObject context) if (rotation % 180 != 0) windowSize = new Size(windowSize.Height, windowSize.Width); - context.SetPreferredSizeFit(windowSize, 0.8); + //edit by gh + context.SetPreferredSizeFit(windowSize, 0.9); + //context.SetPreferredSizeFit(windowSize, 0.8); + //--------// context.TitlebarAutoHide = true; context.Theme = Themes.Dark; diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/QuickLook.Plugin.VideoViewer.csproj b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/QuickLook.Plugin.VideoViewer.csproj index 68937e6b8..97e54a902 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/QuickLook.Plugin.VideoViewer.csproj +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/QuickLook.Plugin.VideoViewer.csproj @@ -84,6 +84,7 @@ ..\..\packages\taglib.2.1.0.0\lib\policy.2.0.taglib-sharp.dll + False @@ -139,6 +140,7 @@ {85fdd6ba-871d-46c8-bd64-f6bb0cb5ea95} QuickLook.Common + False {8b4a9ce5-67b5-4a94-81cb-3771f688fdeb} diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml index c8f53c038..a4c511d42 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml @@ -85,9 +85,11 @@ + + diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs index df13c0786..05ea27db5 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs @@ -54,9 +54,11 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan private bool _isPlaying; private bool _wasPlaying; private bool _shouldLoop; + //add by gh private string _lyric; DispatcherTimer Timer; LrcManager Manager { get; set; } + //------------// public ViewerPanel(ContextObject context) { @@ -101,21 +103,27 @@ public ViewerPanel(ContextObject context) PreviewMouseWheel += (sender, e) => ChangeVolume((double) e.Delta / 120 * 0.04); + //add by gh Manager = new LrcManager(); Timer = new DispatcherTimer(); Timer.Tick += new EventHandler(Timer_Tick); Timer.Interval = new TimeSpan(0, 0, 0, 0, 100); + //-------------// } + //add by gh public string Lyric { get => _lyric; private set { + if (value.Equals(_lyric)) return; _lyric = value; OnPropertyChanged(Lyric); } } + //-----------// + public bool HasVideo { get => _hasVideo; @@ -197,11 +205,15 @@ private void MediaOpened(object o, RoutedEventArgs args) return; HasVideo = mediaElement.HasVideo; - if (!HasVideo) + + //add by gh + if (!HasVideo && !isNullLyric) { Timer.Start(); } else Timer.Stop(); + //----------// + _context.IsBusy = false; } @@ -213,7 +225,8 @@ private void MediaFailed(object sender, MediaFailedEventArgs e) new Label {Content = e.Exception, VerticalAlignment = VerticalAlignment.Center}; _context.IsBusy = false; })); - Timer.Stop(); + + Timer.Stop(); //add by gh } private void MediaEnded(object sender, RoutedEventArgs e) @@ -221,19 +234,26 @@ private void MediaEnded(object sender, RoutedEventArgs e) if (mediaElement == null) return; - Timer.Stop(); mediaElement.MediaPosition = 0; if (ShouldLoop) { IsPlaying = true; mediaElement.Play(); + //add by gh + if(!HasVideo && !isNullLyric) + Timer.Start(); + //--------// } else { IsPlaying = false; mediaElement.Pause(); + //add by gh + if (!HasVideo && !isNullLyric) + Timer.Stop(); + //----------// } } @@ -271,12 +291,14 @@ private void PlayerStateChanged(PlayerState oldState, PlayerState newState) break; } } - private static string[] MediaExtensions = new string[] { ".mp3", ".wav", ".m4a", ".wma", ".aac", ".flac", ".ape", ".opus", ".ogg" }; - private static string[] LyricExtensions = new string[] { ".lrc", ".txt" }; + + //add by gh + private static string[] MusicExtensions = new string[] { ".mp3", ".wav", ".m4a", ".wma", ".aac", ".flac", ".ape", ".opus", ".ogg" }; + bool isNullLyric = false; private void GetLyric(string filename) { var lyricname = string.Empty; - foreach (var ext in MediaExtensions) + foreach (var ext in MusicExtensions) { if (filename.EndsWith(ext)) { @@ -287,7 +309,7 @@ private void GetLyric(string filename) if (!lyricname.Equals(string.Empty) && File.Exists(lyricname)) { if (!Manager.LoadFromFile(lyricname)) - Timer.Stop(); + isNullLyric = true; } else if (filename.EndsWith(".mp3")) //一般只有mp3采用id2tag { @@ -297,10 +319,12 @@ private void GetLyric(string filename) if (lyric != null) { if (!Manager.LoadFromText(lyric)) - Timer.Stop(); + isNullLyric = true; } } } + //-----------------// + private void UpdateMeta(string path, MediaInfo.MediaInfo info) { if (HasVideo) @@ -329,6 +353,7 @@ private void UpdateMeta(string path, MediaInfo.MediaInfo info) ThumbnailOptions.ScaleUp); CoverArt = icon?.ToBitmapSource(); icon?.Dispose(); + GetLyric(path); //---------// //comment by gh @@ -341,7 +366,6 @@ private void UpdateMeta(string path, MediaInfo.MediaInfo info) } */ //-------------// - GetLyric(path); } catch (Exception) { @@ -397,6 +421,7 @@ public void LoadAndPlay(string path, MediaInfo.MediaInfo info) mediaElement.Play(); } + //add by gh /// /// 每个计时器时刻,更新歌词 /// @@ -410,6 +435,7 @@ private void Timer_Tick(object sender, EventArgs e) var current = mediaElement.MediaPosition; metaLyric.Text = Manager.GetNearestLrc(current); } + //---------------// [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) diff --git a/QuickLook/DesktopWatcher.cs b/QuickLook/DesktopWatcher.cs index a25330f70..22a4e319c 100644 --- a/QuickLook/DesktopWatcher.cs +++ b/QuickLook/DesktopWatcher.cs @@ -1,4 +1,5 @@ -using System; +/* create by gh */ +using System; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/README.md b/README.md index bc07f8d2c..eb29277c2 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,15 @@ QuickLook 项目 - edit "PipeServerManager.cs" - add "DesktopWatcher.cs" - edit NativeMethod/QuickLook.cs +- remove Plugin/"WindowsThumbnailProvider.cs" QuickLook.Plugin - VideoViewer - edit "ViewPanel.xaml.cs" - edit "Plugin.cs" -- add "WindowsThumbnailProvider.cs" - update LavFilters 0.72 to 0.74.1 and remove 32 bit version - remove 32 bit version Mediainfo --update MediaInfo.dll and MediaInfo.Wrapper.dll +- update MediaInfo.dll and MediaInfo.Wrapper.dll +- add Lyric folder to achive show lyric line when play music QuickLook.Plugin - ImageViewer - edit "Plugin.cs" @@ -45,8 +46,6 @@ QuickLook.Native - QuickLook.Native64 QuickLook.Common - add "ExtensionMethod/WindowsThumbnailExtension.cs" -- remove [QuickLook.Plugin - VideoViewer] "WindowsThumbnailProvider.cs", and use the same method from here -- remove [QuickLook] Plugin/"WindowsThumbnailProvider.cs" too, and use the same method from here QuickLook.Plugin - PdfViewer - edit "Plugin.cs" @@ -66,6 +65,7 @@ QuickLook.Plugin - PdfViewer 1. 将之前在VideoViewer添加的预览缩略图文件"WindowsThumbnailProvider.cs"移动在QuickLook.Common中并改名为"WindowsThumbnailExtension.cs",并删除QuickLook原有的文件 1. ImageViewer读取不出heif图片大小时使用系统方法 1. 更新MediaViewer里的MediaInfo和MediaInfo.Wrapper +1. 添加音乐界面歌词显示 # QuickLook