Skip to content

Commit

Permalink
Merge pull request #177 from SKProCH/fixNotifyTrackEndedTests
Browse files Browse the repository at this point in the history
Fixes the repeat mode track with NotifyTrackEnded changes
  • Loading branch information
angelobreuer authored Aug 31, 2024
2 parents 241b381 + ea914ff commit ea71c3c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Lavalink4NET/Players/Queued/QueuedLavalinkPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -216,21 +216,20 @@ 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)
{
CurrentItem = null;
}
}

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),
Expand All @@ -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)
{
Expand All @@ -265,24 +264,25 @@ private async ValueTask<Optional<ITrackQueueItem>> GetNextTrackAsync(
int count = 1,
bool respectTrackRepeat = false,
bool respectHistory = false,
ITrackQueueItem? currentItem = null,
CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();

var track = default(Optional<ITrackQueueItem>);

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<ITrackQueueItem>(CurrentItem);
return new Optional<ITrackQueueItem>(currentItem);
}
}

Expand Down

0 comments on commit ea71c3c

Please sign in to comment.