From 8c52e5923bbe87ad1d348a8c9259c0b472526177 Mon Sep 17 00:00:00 2001 From: Angelo Breuer Date: Mon, 11 Mar 2024 19:33:09 +0100 Subject: [PATCH] feat: Implement auto-play feature --- src/Lavalink4NET/Players/Queued/IQueuedLavalinkPlayer.cs | 2 ++ src/Lavalink4NET/Players/Queued/QueuedLavalinkPlayer.cs | 5 ++++- .../Players/Queued/QueuedLavalinkPlayerOptions.cs | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Lavalink4NET/Players/Queued/IQueuedLavalinkPlayer.cs b/src/Lavalink4NET/Players/Queued/IQueuedLavalinkPlayer.cs index 814eda83..70d00eca 100644 --- a/src/Lavalink4NET/Players/Queued/IQueuedLavalinkPlayer.cs +++ b/src/Lavalink4NET/Players/Queued/IQueuedLavalinkPlayer.cs @@ -15,6 +15,8 @@ public interface IQueuedLavalinkPlayer : ILavalinkPlayer bool Shuffle { get; set; } + bool AutoPlay { get; set; } + ValueTask PlayAsync(ITrackQueueItem queueItem, bool enqueue = true, TrackPlayProperties properties = default, CancellationToken cancellationToken = default); ValueTask PlayAsync(LavalinkTrack track, bool enqueue = true, TrackPlayProperties properties = default, CancellationToken cancellationToken = default); diff --git a/src/Lavalink4NET/Players/Queued/QueuedLavalinkPlayer.cs b/src/Lavalink4NET/Players/Queued/QueuedLavalinkPlayer.cs index 07b3c799..4e8bf9e7 100644 --- a/src/Lavalink4NET/Players/Queued/QueuedLavalinkPlayer.cs +++ b/src/Lavalink4NET/Players/Queued/QueuedLavalinkPlayer.cs @@ -41,6 +41,7 @@ public QueuedLavalinkPlayer(IPlayerProperties PlayAsync(ITrackQueueItem queueItem, bool enqueue = true, TrackPlayProperties properties = default, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); @@ -200,7 +203,7 @@ await base .NotifyTrackEndedAsync(queueItem, endReason, cancellationToken) .ConfigureAwait(false); - if (endReason.MayStartNext()) + if (endReason.MayStartNext() && AutoPlay) { await PlayNextAsync(skipCount: 1, respectTrackRepeat: true, cancellationToken).ConfigureAwait(false); } diff --git a/src/Lavalink4NET/Players/Queued/QueuedLavalinkPlayerOptions.cs b/src/Lavalink4NET/Players/Queued/QueuedLavalinkPlayerOptions.cs index 7caae44c..33414e3a 100644 --- a/src/Lavalink4NET/Players/Queued/QueuedLavalinkPlayerOptions.cs +++ b/src/Lavalink4NET/Players/Queued/QueuedLavalinkPlayerOptions.cs @@ -9,6 +9,8 @@ public record class QueuedLavalinkPlayerOptions : LavalinkPlayerOptions public int? HistoryCapacity { get; init; } = 8; + public bool EnableAutoPlay { get; init; } = true; + public bool ClearQueueOnStop { get; init; } = true; public bool ClearHistoryOnStop { get; init; } = false;