From 73a93a7462e9131578a99993bfdf79287ab3a0f0 Mon Sep 17 00:00:00 2001 From: Me on Windows Date: Mon, 5 Jul 2021 19:30:01 +0000 Subject: [PATCH] Re-think what can be played --- QuickPlay/Configuration.cs | 7 ++----- QuickPlay/Interfaces.cs | 6 +++--- QuickPlay/MainActivity.cs | 4 ++-- QuickPlay/MpdPlayer.cs | 14 ++++++++++---- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/QuickPlay/Configuration.cs b/QuickPlay/Configuration.cs index fc3ec1c..056a393 100644 --- a/QuickPlay/Configuration.cs +++ b/QuickPlay/Configuration.cs @@ -233,12 +233,9 @@ namespace QuickPlay Identifier = id; Metadata = new PlayableMetadata { - usualPlayingTime = TimeSpan.Parse(data["time"]) + usualPlayingTime = TimeSpan.Parse(data["time"]), + filePath = data["path"], }; } - public void Play() - { - throw new NotImplementedException(); - } } } \ No newline at end of file diff --git a/QuickPlay/Interfaces.cs b/QuickPlay/Interfaces.cs index 9b3b02b..858aa31 100644 --- a/QuickPlay/Interfaces.cs +++ b/QuickPlay/Interfaces.cs @@ -19,10 +19,10 @@ namespace QuickPlay } Dictionary Songs { get; } string PlayerName { get; } - void Play(string identifier); + Task Play(IPlayable playable); float CurrentProgress { get; } PlayerStatus Status { get; } - void SetReasonableOptions(); //TODO + Task SetReasonableOptions(); /// /// Attach to the real player. /// @@ -43,11 +43,11 @@ namespace QuickPlay public class PlayableMetadata { public TimeSpan usualPlayingTime; + public string filePath; } public interface IPlayable { - void Play(); string Identifier { get; } PlayableMetadata Metadata { get; } } diff --git a/QuickPlay/MainActivity.cs b/QuickPlay/MainActivity.cs index be7b912..d456e0b 100644 --- a/QuickPlay/MainActivity.cs +++ b/QuickPlay/MainActivity.cs @@ -144,9 +144,9 @@ namespace QuickPlay ); } - public void OnSongClick(object sender, IPlayable song) + public async void OnSongClick(object sender, IPlayable song) { - throw new NotImplementedException("Song click."); + await currentPlayer.Play(song); } } } diff --git a/QuickPlay/MpdPlayer.cs b/QuickPlay/MpdPlayer.cs index 4b3dd1c..5c663e6 100644 --- a/QuickPlay/MpdPlayer.cs +++ b/QuickPlay/MpdPlayer.cs @@ -25,13 +25,19 @@ namespace QuickPlay public float CurrentProgress { get { throw new NotImplementedException(); } } - public void Play(string songId) + public async Task Play(IPlayable song) { - throw new NotImplementedException(); + await SetReasonableOptions(); + await mpd.SendAsync(new MpcCore.Commands.Queue.ClearQueue()); + await mpd.SendAsync(new MpcCore.Commands.Queue.AddToQueue(song.Metadata.filePath)); + await mpd.SendAsync(new MpcCore.Commands.Player.Play()); } - public void SetReasonableOptions() + public async Task SetReasonableOptions() { - throw new NotImplementedException(); + await mpd.SendAsync(new MpcCore.Commands.Options.SetConsume(true)); + await mpd.SendAsync(new MpcCore.Commands.Options.SetRandom(false)); + await mpd.SendAsync(new MpcCore.Commands.Options.SetRepeat(false)); + await mpd.SendAsync(new MpcCore.Commands.Options.SetSingle(false)); } public MpdPlayer(PlayerConfiguration cfg) {