From ea914ff590f9b2b77abd7175bae720e9a734e0e2 Mon Sep 17 00:00:00 2001 From: SKProCH Date: Sat, 31 Aug 2024 20:35:40 +0300 Subject: [PATCH] Fixes the repeat mode track with NotifyTrackEnded changes --- .../Players/Queued/QueuedLavalinkPlayer.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Lavalink4NET/Players/Queued/QueuedLavalinkPlayer.cs b/src/Lavalink4NET/Players/Queued/QueuedLavalinkPlayer.cs index 3a8203cf..c18320c7 100644 --- a/src/Lavalink4NET/Players/Queued/QueuedLavalinkPlayer.cs +++ b/src/Lavalink4NET/Players/Queued/QueuedLavalinkPlayer.cs @@ -161,7 +161,7 @@ public virtual ValueTask SkipAsync(int count = 1, CancellationToken cancellation "The count must not be negative."); } - return PlayNextAsync(count, _respectTrackRepeatOnSkip, cancellationToken); + return PlayNextAsync(count, _respectTrackRepeatOnSkip, CurrentItem, cancellationToken); } public override async ValueTask StopAsync(CancellationToken cancellationToken = default) @@ -216,7 +216,7 @@ await base if (endReason.MayStartNext() && AutoPlay) { - await PlayNextAsync(skipCount: 1, respectTrackRepeat: true, cancellationToken).ConfigureAwait(false); + await PlayNextAsync(skipCount: 1, respectTrackRepeat: true, currentItem: queueItem, cancellationToken).ConfigureAwait(false); } else if (endReason is not TrackEndReason.Replaced) { @@ -224,13 +224,12 @@ await base } } - private async ValueTask PlayNextAsync(int skipCount = 1, bool respectTrackRepeat = false, CancellationToken cancellationToken = default) + private async ValueTask PlayNextAsync(int skipCount = 1, bool respectTrackRepeat = false, + ITrackQueueItem? currentItem = null, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); EnsureNotDestroyed(); - var currentItem = CurrentItem; - var respectHistory = _trackHistoryBehavior switch { TrackHistoryBehavior.Adaptive => RepeatMode is TrackRepeatMode.None || (RepeatMode is TrackRepeatMode.Queue && !Queue.IsEmpty), @@ -245,7 +244,7 @@ await Queue .ConfigureAwait(false); } - var track = await GetNextTrackAsync(skipCount, respectTrackRepeat, respectHistory, cancellationToken).ConfigureAwait(false); + var track = await GetNextTrackAsync(skipCount, respectTrackRepeat: respectTrackRepeat, respectHistory: respectHistory, currentItem: currentItem, cancellationToken: cancellationToken).ConfigureAwait(false); if (!track.IsPresent) { @@ -265,24 +264,25 @@ private async ValueTask> GetNextTrackAsync( int count = 1, bool respectTrackRepeat = false, bool respectHistory = false, + ITrackQueueItem? currentItem = null, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); var track = default(Optional); - if (CurrentItem is not null) + if (currentItem is not null) { if (Queue.HasHistory && respectHistory) { await Queue.History - .AddAsync(CurrentItem, cancellationToken) + .AddAsync(currentItem, cancellationToken) .ConfigureAwait(false); } if (respectTrackRepeat && RepeatMode is TrackRepeatMode.Track) { - return new Optional(CurrentItem); + return new Optional(currentItem); } }