From 7aafa935e19facf02c787dc77aca53b1cbd7a4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Marchal?= Date: Sun, 3 Oct 2021 17:20:14 +0200 Subject: [PATCH] Fix mpd bug execution with radios --- Handlers/MPDHandler.cs | 7 +++++++ Views/Radios.xaml.cs | 26 +++++--------------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/Handlers/MPDHandler.cs b/Handlers/MPDHandler.cs index 3203c4e..7a5fc3e 100644 --- a/Handlers/MPDHandler.cs +++ b/Handlers/MPDHandler.cs @@ -13,6 +13,7 @@ using MpcNET; using MpcNET.Commands.Database; using MpcNET.Commands.Playback; using MpcNET.Commands.Queue; +using MpcNET.Commands.Reflection; using MpcNET.Commands.Status; using MpcNET.Message; using MpcNET.Types; @@ -456,5 +457,11 @@ namespace unison Debug.WriteLine("AddCommand path: " + Uri); SendCommand(new AddCommand(Uri)); } + + public void ClearAddAndPlay(string Uri) + { + CommandList commandList = new CommandList(new IMpcCommand[] { new ClearCommand(), new AddCommand(Uri), new PlayCommand(0) }); + SendCommand(commandList); + } } } \ No newline at end of file diff --git a/Views/Radios.xaml.cs b/Views/Radios.xaml.cs index bf5429a..ef23fd5 100644 --- a/Views/Radios.xaml.cs +++ b/Views/Radios.xaml.cs @@ -15,7 +15,7 @@ namespace unison { public class CountryListItem { - public uint Count { get; set; } + public uint Count { get; set; } public string Name { get; set; } public override string ToString() @@ -31,6 +31,7 @@ namespace unison public string Name { get; set; } public string Codec { get; set; } public string Tags { get; set; } + public int Bitrate { get; set; } public Uri Url { get; set; } private string _country; @@ -47,21 +48,6 @@ namespace unison _country = value; } } - - private string _bitrate; - public string Bitrate - { - get - { - if (_bitrate == "0") - return "—"; - return _bitrate.ToString(); - } - set - { - _bitrate = value; - } - } } public partial class Radios : Window @@ -119,7 +105,7 @@ namespace unison Name = CleanString(station.Name), Country = station.CountryCode, Codec = station.Codec, - Bitrate = station.Bitrate.ToString(), + Bitrate = station.Bitrate, Url = station.Url, Tags = string.Join(", ", station.Tags) }); @@ -144,7 +130,7 @@ namespace unison { station = grid.Items[grid.SelectedIndex] as StationListItem; } - catch (System.ArgumentOutOfRangeException) + catch (ArgumentOutOfRangeException) { Debug.WriteLine("Error: Invalid index."); return; @@ -157,9 +143,7 @@ namespace unison } _mpd = (MPDHandler)Application.Current.Properties["mpd"]; - _mpd.ClearQueue(); - _mpd.AddSong(station.Url.AbsoluteUri); - _mpd.PlayCommand(); + _mpd.ClearAddAndPlay(station.Url.AbsoluteUri); } private async void Search_Clicked(object sender, RoutedEventArgs e)