-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdate.cs
125 lines (107 loc) · 4.97 KB
/
Update.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Drawing;
using System.Windows.Forms;
using WMPLib;
namespace Spotifly
{
public partial class Form1
{
// Freq * timer.Interval for ms
private int timesUpdated = 1;
private readonly int slowUpdateFreq = 27, midUpdateFreq = 5;
private readonly Timer timer = new Timer();
private void UpdatesStart()
{
timer.Interval = 50;
timer.Tick += Update;
timer.Start();
axWindowsMediaPlayer.settings.volume = Properties.Settings.Default.LastSessionVolume;
}
private void Update(object sender, EventArgs e)
{
timesUpdated++;
FastUpdate();
switch (UpdateTier())
{
case 2:
MidUpdate();
break;
case 3:
MidUpdate();
SlowUpdate();
break;
}
timesUpdated *= Convert.ToInt32(timesUpdated < slowUpdateFreq);
int UpdateTier()
{//higher tiers means they repeat less often
bool tier3 = timesUpdated % (slowUpdateFreq + 0.0) == 0;
bool tier2 = timesUpdated % (midUpdateFreq + 0.0) == 0;
int tier = Convert.ToInt32(tier3) * 3
+ Convert.ToInt32(tier2 && !tier3) * 2
+ Convert.ToInt32(!tier3 && !tier2);
return tier;
}
}
private void FastUpdate()
{
try
{
SetProgressBarValueForCurrentMediaPos();
string elapsedTime = showRemainingTimeInElapsed ? GetRemainingTimeString() : axWindowsMediaPlayer.Ctlcontrols.currentPositionString;
ElapsedTimeLabel.Text = string.IsNullOrWhiteSpace(elapsedTime) || string.IsNullOrWhiteSpace(axWindowsMediaPlayer.URL) ? "00:00" : elapsedTime;
GetColorsForTheme(currentTheme, out _, out _, out _, out Color ButtonColor, out _);
if (isPlaying && !isPcLocked)
{
if (axWindowsMediaPlayer.playState != WMPPlayState.wmppsPlaying)
axWindowsMediaPlayer.Ctlcontrols.play();
PlayBttn.Image = SubstituteNotBlankFromImage(Properties.Resources.Pause, ButtonColor);
}
else
{
if (axWindowsMediaPlayer.playState != WMPPlayState.wmppsPaused)
axWindowsMediaPlayer.Ctlcontrols.pause();
PlayBttn.Image = SubstituteNotBlankFromImage(Properties.Resources.Playy, ButtonColor);
}
}
catch
{ }
}
private void MidUpdate()
{
if (axWindowsMediaPlayer.uiMode != "none" && !axWindowsMediaPlayer.fullScreen)
axWindowsMediaPlayer.uiMode = "none";
try
{
if (MinimumSize.Width == verticalModeMinWidth && ResizeForMediaCheckBox.Checked && panels[0].Visible)
{
MinimumSize = new Size(normalMinWidth, MinimumSize.Height);
SetFormSizeForCurrentMedia();
}
VolumeTrackBar.Value = axWindowsMediaPlayer.settings.volume;
MediaLengthLabel.Location = new Point(Width - (initialMediaLengthLabelDistanceToFormEnd + MediaLengthLabel.Width), MediaLengthLabel.Location.Y);
if (!isQueued || CheckMediaIndexWithSongQueueCheckBox.Checked)
CheckPlaylistIndex();
/*if (axWindowsMediaPlayer.playState == WMPPlayState.wmppsReady || axWindowsMediaPlayer.playState == WMPPlayState.wmppsPaused || axWindowsMediaPlayer.playState == WMPPlayState.wmppsStopped ||
axWindowsMediaPlayer.playState == WMPPlayState.wmppsUndefined)
PlayBttn.Image = SubstituteNotBlankFromImage(Properties.Resources.Playy, ButtonColor);
else if (axWindowsMediaPlayer.playState != WMPPlayState.wmppsScanForward && axWindowsMediaPlayer.playState != WMPPlayState.wmppsScanReverse)
PlayBttn.Image = SubstituteNotBlankFromImage(Properties.Resources.Pause, ButtonColor);*/
MediaLengthLabel.Text = axWindowsMediaPlayer.currentMedia.durationString;
EnableTabIndex(activePanelIndex != 0);
void EnableTabIndex(bool value)
{
foreach (Control formControl in MainForm.Controls)
foreach (Control control in formControl.Controls)
control.TabStop = value;
PlayBttn.TabStop = true;
}
}
catch
{ }
}
private void SlowUpdate()
{
MediaListView_DrawMedia(fileFilterMemory);
}
}
}