Fix mpd bug execution with radios

This commit is contained in:
Théo Marchal 2021-10-03 17:20:14 +02:00
parent 2960afd9bd
commit 7aafa935e1
2 changed files with 12 additions and 21 deletions

View File

@ -13,6 +13,7 @@ using MpcNET;
using MpcNET.Commands.Database; using MpcNET.Commands.Database;
using MpcNET.Commands.Playback; using MpcNET.Commands.Playback;
using MpcNET.Commands.Queue; using MpcNET.Commands.Queue;
using MpcNET.Commands.Reflection;
using MpcNET.Commands.Status; using MpcNET.Commands.Status;
using MpcNET.Message; using MpcNET.Message;
using MpcNET.Types; using MpcNET.Types;
@ -456,5 +457,11 @@ namespace unison
Debug.WriteLine("AddCommand path: " + Uri); Debug.WriteLine("AddCommand path: " + Uri);
SendCommand(new AddCommand(Uri)); SendCommand(new AddCommand(Uri));
} }
public void ClearAddAndPlay(string Uri)
{
CommandList commandList = new CommandList(new IMpcCommand<object>[] { new ClearCommand(), new AddCommand(Uri), new PlayCommand(0) });
SendCommand(commandList);
}
} }
} }

View File

@ -31,6 +31,7 @@ namespace unison
public string Name { get; set; } public string Name { get; set; }
public string Codec { get; set; } public string Codec { get; set; }
public string Tags { get; set; } public string Tags { get; set; }
public int Bitrate { get; set; }
public Uri Url { get; set; } public Uri Url { get; set; }
private string _country; private string _country;
@ -47,21 +48,6 @@ namespace unison
_country = value; _country = value;
} }
} }
private string _bitrate;
public string Bitrate
{
get
{
if (_bitrate == "0")
return "—";
return _bitrate.ToString();
}
set
{
_bitrate = value;
}
}
} }
public partial class Radios : Window public partial class Radios : Window
@ -119,7 +105,7 @@ namespace unison
Name = CleanString(station.Name), Name = CleanString(station.Name),
Country = station.CountryCode, Country = station.CountryCode,
Codec = station.Codec, Codec = station.Codec,
Bitrate = station.Bitrate.ToString(), Bitrate = station.Bitrate,
Url = station.Url, Url = station.Url,
Tags = string.Join(", ", station.Tags) Tags = string.Join(", ", station.Tags)
}); });
@ -144,7 +130,7 @@ namespace unison
{ {
station = grid.Items[grid.SelectedIndex] as StationListItem; station = grid.Items[grid.SelectedIndex] as StationListItem;
} }
catch (System.ArgumentOutOfRangeException) catch (ArgumentOutOfRangeException)
{ {
Debug.WriteLine("Error: Invalid index."); Debug.WriteLine("Error: Invalid index.");
return; return;
@ -157,9 +143,7 @@ namespace unison
} }
_mpd = (MPDHandler)Application.Current.Properties["mpd"]; _mpd = (MPDHandler)Application.Current.Properties["mpd"];
_mpd.ClearQueue(); _mpd.ClearAddAndPlay(station.Url.AbsoluteUri);
_mpd.AddSong(station.Url.AbsoluteUri);
_mpd.PlayCommand();
} }
private async void Search_Clicked(object sender, RoutedEventArgs e) private async void Search_Clicked(object sender, RoutedEventArgs e)