Cleaned things for shuffle, but still has some deadlocks and crashes

This commit is contained in:
2022-04-18 01:02:26 +02:00
parent 792437b839
commit 1d3515a39d
6 changed files with 231 additions and 201 deletions

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
@ -34,7 +35,7 @@ namespace unison
public class MPDHandler
{
private bool _connected;
public string _version;
private string _version;
private int _currentVolume;
private int _previousVolume;
private bool _currentRandom;
@ -43,6 +44,7 @@ namespace unison
private bool _currentConsume;
private double _currentTime;
private double _totalTime;
private IEnumerable<IMpdFile> _Playlist;
private MpdStatus _currentStatus;
private IMpdFile _currentSong;
@ -155,9 +157,7 @@ namespace unison
try
{
Debug.WriteLine("SafelySendCommandAsync => before command");
IMpdMessage<T> response = await _commandConnection.SendAsync(command);
Debug.WriteLine("SafelySendCommandAsync => after command");
if (!response.IsResponseValid)
{
string mpdError = response.Response?.Result?.MpdError;
@ -492,14 +492,26 @@ namespace unison
public string GetVersion() => _version;
public Statistics GetStats() => _stats;
public double GetCurrentTime() => _currentTime;
public IEnumerable<IMpdFile> GetPlaylist() => _Playlist;
public bool IsConnected() => _connected;
public bool IsPlaying() => _currentStatus?.State == MpdState.Play;
public void Prev() => SendCommand(new PreviousCommand());
public void Next() => SendCommand(new NextCommand());
public void PlayPause() => SendCommand(new PauseResumeCommand());
public bool CanPrevNext = true;
public void Prev()
{
if (CanPrevNext)
SendCommand(new PreviousCommand());
}
public void Next()
{
if (CanPrevNext)
SendCommand(new NextCommand());
}
public void PlayPause() => SendCommand(new PauseResumeCommand());
public void Play(int pos) => SendCommand(new PlayCommand(pos));
public void Random() => SendCommand(new RandomCommand(!_currentRandom));
@ -555,6 +567,15 @@ namespace unison
SendCommand(commandList);
}
public async Task QueryPlaylist() => _Playlist = await SafelySendCommandAsync(new PlaylistCommand());
public int GetPlaylistCount()
{
if (_Playlist == null)
return 0;
return _Playlist.ToArray().Count();
}
public async void QueryStats()
{
Dictionary<string, string> Response = await SafelySendCommandAsync(new StatsCommand());