Skip to content

Commit 10298f1

Browse files
committed
feat(ui): supports taskbar progress display [Fixes #34]
1 parent cb9605a commit 10298f1

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

LLPlayer/ViewModels/MainWindowVM.cs

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.IO;
2+
using System.Windows.Shell;
23
using FlyleafLib;
34
using FlyleafLib.MediaPlayer;
45
using LLPlayer.Extensions;
@@ -20,6 +21,25 @@ public MainWindowVM(FlyleafManager fl)
2021

2122
public string Title { get; set => Set(ref field, value); } = App.Name;
2223

24+
#region Progress in TaskBar
25+
public double TaskBarProgressValue
26+
{
27+
get;
28+
set
29+
{
30+
double v = value;
31+
if (v < 0.01)
32+
{
33+
// Set to 1% because it is not displayed.
34+
v = 0.01;
35+
}
36+
Set(ref field, v);
37+
}
38+
}
39+
40+
public TaskbarItemProgressState TaskBarProgressState { get; set => Set(ref field, value); }
41+
#endregion
42+
2343
// ReSharper disable NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract
2444
public DelegateCommand CmdOnLoaded => field ??= new(() =>
2545
{
@@ -44,12 +64,43 @@ public MainWindowVM(FlyleafManager fl)
4464

4565
FL.Player.PropertyChanged += (sender, args) =>
4666
{
67+
if (args.PropertyName == nameof(FL.Player.CurTime))
68+
{
69+
double prevValue = TaskBarProgressValue;
70+
double newValue = (double)FL.Player.CurTime / FL.Player.Duration;
71+
72+
if (Math.Abs(newValue - prevValue) >= 0.01) // prevent frequent update
73+
{
74+
TaskBarProgressValue = newValue;
75+
}
76+
}
4777
if (args.PropertyName == nameof(FL.Player.Status))
4878
{
49-
if (FL.Player.Status == Status.Stopped)
79+
switch (FL.Player.Status)
5080
{
51-
// reset
52-
Title = App.Name;
81+
case Status.Stopped:
82+
// reset
83+
Title = App.Name;
84+
TaskBarProgressState = TaskbarItemProgressState.None;
85+
TaskBarProgressValue = 0;
86+
break;
87+
case Status.Playing:
88+
TaskBarProgressState = TaskbarItemProgressState.Normal;
89+
break;
90+
case Status.Opening:
91+
TaskBarProgressState = TaskbarItemProgressState.Indeterminate;
92+
TaskBarProgressValue = 0;
93+
break;
94+
case Status.Paused:
95+
TaskBarProgressState = TaskbarItemProgressState.Paused;
96+
break;
97+
case Status.Ended:
98+
TaskBarProgressState = TaskbarItemProgressState.Paused;
99+
TaskBarProgressValue = 1;
100+
break;
101+
case Status.Failed:
102+
TaskBarProgressState = TaskbarItemProgressState.Error;
103+
break;
53104
}
54105
}
55106
};
@@ -67,6 +118,8 @@ public MainWindowVM(FlyleafManager fl)
67118
name = FL.Player.Playlist.Selected.Title;
68119
}
69120
Title = $"{name} - {App.Name}";
121+
TaskBarProgressValue = 0;
122+
TaskBarProgressState = TaskbarItemProgressState.Normal;
70123
};
71124

72125
if (App.CmdUrl != null)

LLPlayer/Views/MainWindow.xaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
</i:EventTrigger>
2727
</i:Interaction.Triggers>
2828

29+
<!-- Progress display of taskbar icon -->
30+
<Window.TaskbarItemInfo>
31+
<TaskbarItemInfo
32+
ProgressValue="{Binding TaskBarProgressValue}"
33+
ProgressState="{Binding TaskBarProgressState}" />
34+
</Window.TaskbarItemInfo>
35+
2936
<Grid>
3037
<!-- Swap Sidebar Left/Right -->
3138
<Grid.Style>

0 commit comments

Comments
 (0)