Working mpd handling, even if I'm not a big fan of it
This commit is contained in:
@ -25,7 +25,7 @@
|
||||
<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"/>
|
||||
<TextBlock x:Name="Bitrate" TextWrapping="Wrap" TextAlignment="Center" FontWeight="Normal" Text="Bitrate" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<Grid x:Name="Controls" VerticalAlignment="Top" Margin="10,106,10,0">
|
||||
@ -93,7 +93,8 @@
|
||||
<StackPanel.OpacityMask>
|
||||
<VisualBrush Visual="{Binding ElementName=mask}"/>
|
||||
</StackPanel.OpacityMask>
|
||||
<Image HorizontalAlignment="Center" VerticalAlignment="Center" Source="/images/nocover.png" />
|
||||
<Image x:Name="Cover" HorizontalAlignment="Center" VerticalAlignment="Center" Source="/images/nocover.png" Visibility="Collapsed" />
|
||||
<Image x:Name="NoCover" HorizontalAlignment="Center" VerticalAlignment="Center" Source="/images/nocover.png" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
@ -1,20 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Threading;
|
||||
using System.Windows.Interop;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace unison
|
||||
{
|
||||
public partial class MainWindow : Window
|
||||
public partial class MainWindow : Window, INotifyPropertyChanged
|
||||
{
|
||||
private readonly Settings SettingsWindow = new Settings();
|
||||
|
||||
private readonly MPDHandler mpd;
|
||||
private MPDHandler mpd;
|
||||
|
||||
Thickness SelectedThickness;
|
||||
Thickness BaseThickness;
|
||||
@ -27,10 +24,9 @@ namespace unison
|
||||
WindowState = WindowState.Minimized;
|
||||
|
||||
mpd = (MPDHandler)Application.Current.Properties["mpd"];
|
||||
mpd.Connect();
|
||||
|
||||
DispatcherTimer timer = new DispatcherTimer();
|
||||
timer.Interval = TimeSpan.FromSeconds(0.2);
|
||||
timer.Interval = TimeSpan.FromSeconds(0.5);
|
||||
timer.Tick += Timer_Tick;
|
||||
timer.Start();
|
||||
|
||||
@ -41,9 +37,6 @@ namespace unison
|
||||
|
||||
private void Timer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
MPDHandler mpd = (MPDHandler)Application.Current.Properties["mpd"];
|
||||
mpd.Loop();
|
||||
|
||||
UpdateInterface();
|
||||
}
|
||||
|
||||
@ -63,7 +56,7 @@ namespace unison
|
||||
|
||||
public void UpdateInterface()
|
||||
{
|
||||
if (mpd.GetCurrentSong() != null)
|
||||
if (mpd.GetCurrentSong() != null && mpd.GetStatus() != null)
|
||||
{
|
||||
SongTitle.Text = mpd.GetCurrentSong().Title;
|
||||
SongTitle.ToolTip = mpd.GetCurrentSong().File;
|
||||
@ -74,11 +67,11 @@ namespace unison
|
||||
Bitrate.Text = mpd.GetCurrentSong().File.Substring(mpd.GetCurrentSong().File.LastIndexOf(".") + 1) + " – ";
|
||||
Bitrate.Text += mpd.GetStatus().MpdBitrate + "kbps";
|
||||
|
||||
CurrentTime.Text = FormatSeconds(mpd._currentElapsed);
|
||||
CurrentTime.Text = FormatSeconds(mpd._elapsed);
|
||||
EndTime.Text = FormatSeconds(mpd.GetStatus().MpdSongTime);
|
||||
|
||||
if (!System.Double.IsNaN(mpd.GetCurrentSong().TimeSort))
|
||||
TimeSlider.Value = mpd._currentElapsed / mpd.GetCurrentSong().TimeSort * 100;
|
||||
TimeSlider.Value = mpd._elapsed / mpd.GetCurrentSong().TimeSort * 100;
|
||||
}
|
||||
|
||||
if (VolumeSlider.Value != mpd._currentVolume)
|
||||
@ -104,11 +97,28 @@ namespace unison
|
||||
UpdateButton(ref BorderRepeat, mpd._currentRepeat);
|
||||
UpdateButton(ref BorderSingle, mpd._currentSingle);
|
||||
UpdateButton(ref BorderConsume, mpd._currentConsume);
|
||||
|
||||
if (mpd.GetCover() != null)
|
||||
{
|
||||
if ((!mpd.GetCover().IsDownloading) && mpd.GetCover().IsSuccess)
|
||||
{
|
||||
if (mpd.GetCurrentSong().File == mpd.GetCover().SongFilePath)
|
||||
{
|
||||
Cover.Source = mpd.GetCover().AlbumImageSource;
|
||||
Cover.Visibility = Visibility.Visible;
|
||||
NoCover.Visibility = Visibility.Collapsed;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
NoCover.Visibility = Visibility.Visible;
|
||||
Cover.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public void Pause_Clicked(object sender, RoutedEventArgs e) => mpd.PlayPause();
|
||||
public void Previous_Clicked(object sender, RoutedEventArgs e) => mpd.Prev();
|
||||
public void Next_Clicked(object sender, RoutedEventArgs e) => mpd.Next();
|
||||
|
||||
public void Random_Clicked(object sender, RoutedEventArgs e) => mpd.Random();
|
||||
public void Repeat_Clicked(object sender, RoutedEventArgs e) => mpd.Repeat();
|
||||
public void Single_Clicked(object sender, RoutedEventArgs e) => mpd.Single();
|
||||
@ -152,5 +162,12 @@ namespace unison
|
||||
WindowInteropHelper helper = new(this);
|
||||
helper.EnsureHandle();
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
@ -46,7 +46,7 @@ namespace unison
|
||||
|
||||
MpdHost.Text = Properties.Settings.Default.mpd_host;
|
||||
MpdPort.Text = Properties.Settings.Default.mpd_port.ToString();
|
||||
MpdPassword.Text = Properties.Settings.Default.mpd_password;
|
||||
MpdPassword.Text = null; //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();
|
||||
@ -70,7 +70,7 @@ namespace unison
|
||||
{
|
||||
SaveSettings();
|
||||
MPDHandler mpd = (MPDHandler)Application.Current.Properties["mpd"];
|
||||
mpd.Connect();
|
||||
//mpd.Connect();
|
||||
}
|
||||
|
||||
private void SnapcastReset_Clicked(object sender, RoutedEventArgs e)
|
||||
@ -83,7 +83,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 = MpdPassword.Text;
|
||||
Properties.Settings.Default.mpd_password = null;//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