Skip to content

Commit

Permalink
add lyric line in VideoViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
SplitGemini committed Apr 30, 2020
1 parent 46809ca commit 6e4f62b
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 41 deletions.
3 changes: 1 addition & 2 deletions QuickLook.Installer/QuickLook.Installer.wixproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ powershell -file "$(SolutionDir)Scripts\pack-zip.ps1"
rmdir /S /Q "$(SolutionDir)Build\Package"</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PreBuildEvent>powershell -file "$(SolutionDir)Scripts\rename-msi.ps1"
rmdir /S /Q "$(SolutionDir)Build\Package"
<PreBuildEvent>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"</PreBuildEvent>
Expand Down
4 changes: 2 additions & 2 deletions QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 2 additions & 16 deletions QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Lyric/LrcLine.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
/* create by gh */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
/* create by gh */
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down
13 changes: 8 additions & 5 deletions QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,17 +61,17 @@ 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(
//Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
//Environment.Is64BitProcess ? "MediaInfo-x64\\" : "MediaInfo-x86\\"));
//----------//

//-----comment by gh---
//comment by gh
//_mediaInfo.Option("Cover_Data", "base64");
//---------------------
//---------------------//

_mediaInfo.Open(path);

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
</Reference>
<Reference Include="policy.2.0.taglib-sharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=db62eba44689b5b0, processorArchitecture=MSIL">
<HintPath>..\..\packages\taglib.2.1.0.0\lib\policy.2.0.taglib-sharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -139,6 +140,7 @@
<ProjectReference Include="..\..\QuickLook.Common\QuickLook.Common.csproj">
<Project>{85fdd6ba-871d-46c8-bd64-f6bb0cb5ea95}</Project>
<Name>QuickLook.Common</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\QuickLook\QuickLook.csproj">
<Project>{8b4a9ce5-67b5-4a94-81cb-3771f688fdeb}</Project>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@
<TextBlock x:Name="metaLength" Grid.Row="5" FontSize="14" Padding="3" TextTrimming="CharacterEllipsis"
Foreground="{DynamicResource WindowTextForeground}"
Text="{Binding ElementName=mediaElement, Path=MediaDuration, Converter={StaticResource TimeTickToShortStringConverter}}" />
<!-- add by gh -->
<TextBlock x:Name="metaLyric" Grid.Row="6" FontSize="14" Padding="3" TextTrimming="CharacterEllipsis"
Foreground="{DynamicResource WindowTextForeground}"
Text="{Binding Lyric, ElementName=viewerPanel}" TextWrapping="Wrap"/>
<!-- -->
</Grid>
</Grid>

Expand Down
44 changes: 35 additions & 9 deletions QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -213,27 +225,35 @@ 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)
{
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();
//----------//
}
}

Expand Down Expand Up @@ -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))
{
Expand All @@ -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
{
Expand All @@ -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)
Expand Down Expand Up @@ -329,6 +353,7 @@ private void UpdateMeta(string path, MediaInfo.MediaInfo info)
ThumbnailOptions.ScaleUp);
CoverArt = icon?.ToBitmapSource();
icon?.Dispose();
GetLyric(path);
//---------//

//comment by gh
Expand All @@ -341,7 +366,6 @@ private void UpdateMeta(string path, MediaInfo.MediaInfo info)
}
*/
//-------------//
GetLyric(path);
}
catch (Exception)
{
Expand Down Expand Up @@ -397,6 +421,7 @@ public void LoadAndPlay(string path, MediaInfo.MediaInfo info)
mediaElement.Play();
}

//add by gh
/// <summary>
/// 每个计时器时刻,更新歌词
/// </summary>
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion QuickLook/DesktopWatcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
/* create by gh */
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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

Expand Down

0 comments on commit 6e4f62b

Please sign in to comment.