UI is now updated through MPD events and not every second + misc fixes
This commit is contained in:
@ -25,7 +25,11 @@
|
||||
<TextBlock x:Name="SongTitle" TextWrapping="Wrap" TextAlignment="Center" FontWeight="Normal" FontSize="20" Text="Title"/>
|
||||
<TextBlock x:Name="SongArtist" TextWrapping="Wrap" TextAlignment="Center" FontWeight="Bold" FontSize="18" Text="Artist"/>
|
||||
<TextBlock x:Name="SongAlbum" TextWrapping="Wrap" TextAlignment="Center" FontWeight="Normal" FontSize="16" Text="Album"/>
|
||||
<TextBlock x:Name="Bitrate" TextWrapping="Wrap" TextAlignment="Center" FontWeight="Normal" Text="Bitrate" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}"/>
|
||||
<TextBlock TextWrapping="Wrap" TextAlignment="Center" FontWeight="Normal" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" Margin="0,2,0,0">
|
||||
<Run x:Name="SongGenre"/>
|
||||
<Run> – </Run>
|
||||
<Run x:Name="Format"/>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<Grid x:Name="Controls" VerticalAlignment="Top" Margin="10,95,10,0">
|
||||
@ -99,7 +103,7 @@
|
||||
</Border>
|
||||
</Grid>
|
||||
<Grid x:Name="BottomLayout" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}" Width="Auto" MinHeight="40">
|
||||
<Button x:Name="Snapcast" HorizontalAlignment="Left" VerticalAlignment="Center" Click="Snapcast_Clicked" Margin="10,0,0,0" Padding="5, 2" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" FocusVisualStyle="{x:Null}">
|
||||
<Button x:Name="Snapcast" HorizontalAlignment="Left" VerticalAlignment="Center" Click="Snapcast_Clicked" Margin="10,0,0,0" Padding="5, 2" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" FocusVisualStyle="{x:Null}" IsEnabled="False">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<emoji:TextBlock Text="🔊" Padding="0,0,0,2"/>
|
||||
<TextBlock x:Name="SnapcastText" Text="Start Snapcast" Margin="5, 0, 0, 0"/>
|
||||
|
@ -12,7 +12,7 @@ namespace unison
|
||||
{
|
||||
public readonly Settings SettingsWindow = new Settings();
|
||||
|
||||
private MPDHandler mpd;
|
||||
private readonly MPDHandler mpd;
|
||||
|
||||
Thickness SelectedThickness;
|
||||
Thickness BaseThickness;
|
||||
@ -38,7 +38,11 @@ namespace unison
|
||||
|
||||
private void Timer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
UpdateInterface();
|
||||
if (mpd.GetCurrentSong() == null)
|
||||
return;
|
||||
|
||||
CurrentTime.Text = FormatSeconds(mpd._currentTime);
|
||||
TimeSlider.Value = mpd._currentTime / mpd.GetCurrentSong().Time * 100;
|
||||
}
|
||||
|
||||
public void UpdateButton(ref Border border, bool b)
|
||||
@ -60,24 +64,39 @@ namespace unison
|
||||
return timespan.ToString(@"mm\:ss");
|
||||
}
|
||||
|
||||
public void UpdateInterface()
|
||||
public void OnConnectionChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (mpd.GetCurrentSong() == null || mpd.GetStatus() == null)
|
||||
Connection.Text = (mpd._connected ? "✔️" : "❌") + $"{Properties.Settings.Default.mpd_host}:{Properties.Settings.Default.mpd_port}";
|
||||
SettingsWindow.UpdateConnectionStatus();
|
||||
if (mpd._connected)
|
||||
Snapcast.IsEnabled = true;
|
||||
}
|
||||
|
||||
public void OnSongChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (mpd.GetCurrentSong() == null)
|
||||
return;
|
||||
|
||||
SongTitle.Text = mpd.GetCurrentSong().Title;
|
||||
if (!mpd.GetCurrentSong().HasName)
|
||||
SongTitle.Text = mpd.GetCurrentSong().Title;
|
||||
else
|
||||
SongTitle.Text = mpd.GetCurrentSong().Title;
|
||||
SongTitle.ToolTip = mpd.GetCurrentSong().Path;
|
||||
SongArtist.Text = mpd.GetCurrentSong().Artist;
|
||||
SongAlbum.Text = mpd.GetCurrentSong().Album;
|
||||
SongGenre.Text = mpd.GetCurrentSong().Genre;
|
||||
|
||||
if (mpd.GetCurrentSong().Date != null)
|
||||
SongAlbum.Text += $" ({ mpd.GetCurrentSong().Date})";
|
||||
Bitrate.Text = mpd.GetCurrentSong().Path.Substring(mpd.GetCurrentSong().Path.LastIndexOf(".") + 1) + " – ";
|
||||
Bitrate.Text += mpd.GetStatus().Bitrate + "kbps";
|
||||
Format.Text = mpd.GetCurrentSong().Path.Substring(mpd.GetCurrentSong().Path.LastIndexOf(".") + 1);
|
||||
|
||||
CurrentTime.Text = FormatSeconds(mpd._currentTime);
|
||||
EndTime.Text = FormatSeconds(mpd.GetCurrentSong().Time);
|
||||
}
|
||||
|
||||
TimeSlider.Value = mpd._currentTime / mpd.GetCurrentSong().Time * 100;
|
||||
public void OnStatusChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (mpd.GetStatus() == null)
|
||||
return;
|
||||
|
||||
if (VolumeSlider.Value != mpd._currentVolume)
|
||||
{
|
||||
@ -90,13 +109,14 @@ namespace unison
|
||||
else
|
||||
PlayPause.Text = "\xedb5";
|
||||
|
||||
Connection.Text = (mpd._connected ? "✔️" : "❌") + $"{Properties.Settings.Default.mpd_host}:{Properties.Settings.Default.mpd_port}";
|
||||
|
||||
UpdateButton(ref BorderRandom, mpd._currentRandom);
|
||||
UpdateButton(ref BorderRepeat, mpd._currentRepeat);
|
||||
UpdateButton(ref BorderSingle, mpd._currentSingle);
|
||||
UpdateButton(ref BorderConsume, mpd._currentConsume);
|
||||
}
|
||||
|
||||
public void OnCoverChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (mpd.GetCover() == null)
|
||||
{
|
||||
NoCover.Visibility = Visibility.Visible;
|
||||
@ -108,7 +128,10 @@ namespace unison
|
||||
Cover.Visibility = Visibility.Visible;
|
||||
NoCover.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSnapcastChanged()
|
||||
{
|
||||
SnapcastHandler snapcast = (SnapcastHandler)Application.Current.Properties["snapcast"];
|
||||
if (snapcast.Started)
|
||||
SnapcastText.Text = "Stop Snapcast";
|
||||
|
@ -46,7 +46,7 @@ namespace unison
|
||||
|
||||
MpdHost.Text = Properties.Settings.Default.mpd_host;
|
||||
MpdPort.Text = Properties.Settings.Default.mpd_port.ToString();
|
||||
MpdPassword.Text = null; //Properties.Settings.Default.mpd_password;
|
||||
MpdPassword.Text = Properties.Settings.Default.mpd_password;
|
||||
SnapcastStartup.IsChecked = Properties.Settings.Default.snapcast_startup;
|
||||
SnapcastPath.Text = Properties.Settings.Default.snapcast_path;
|
||||
SnapcastPort.Text = Properties.Settings.Default.snapcast_port.ToString();
|
||||
@ -71,18 +71,17 @@ namespace unison
|
||||
{
|
||||
MPDHandler mpd = (MPDHandler)Application.Current.Properties["mpd"];
|
||||
if (mpd._connected)
|
||||
{
|
||||
ConnectionStatus.Text = "Connected to MPD " + mpd.GetVersion() + ".";
|
||||
ConnectButton.IsEnabled = false;
|
||||
}
|
||||
else
|
||||
ConnectionStatus.Text = "Not connected.";
|
||||
}
|
||||
|
||||
private void MPDConnect_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SaveSettings();
|
||||
ConnectionStatus.Text = "Connecting...";
|
||||
MPDHandler mpd = (MPDHandler)Application.Current.Properties["mpd"];
|
||||
// connect to mpd
|
||||
UpdateConnectionStatus();
|
||||
mpd.Connect();
|
||||
}
|
||||
|
||||
private void SnapcastReset_Clicked(object sender, RoutedEventArgs e)
|
||||
@ -95,7 +94,7 @@ namespace unison
|
||||
{
|
||||
Properties.Settings.Default.mpd_host = MpdHost.Text;
|
||||
Properties.Settings.Default.mpd_port = int.Parse(MpdPort.Text, CultureInfo.InvariantCulture);
|
||||
Properties.Settings.Default.mpd_password = null;//MpdPassword.Text;
|
||||
Properties.Settings.Default.mpd_password = MpdPassword.Text;
|
||||
Properties.Settings.Default.snapcast_startup = (bool)SnapcastStartup.IsChecked;
|
||||
Properties.Settings.Default.snapcast_path = SnapcastPath.Text;
|
||||
Properties.Settings.Default.snapcast_port = int.Parse(SnapcastPort.Text, CultureInfo.InvariantCulture);
|
||||
|
Reference in New Issue
Block a user