Skip to content

Commit

Permalink
Merge pull request #169 from SKProCH/fixOverridenTracks
Browse files Browse the repository at this point in the history
Fixes queue items correlation when playable track identifier differs …
  • Loading branch information
angelobreuer authored Aug 21, 2024
2 parents c62c428 + d24b65a commit ce1543b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Lavalink4NET/Players/LavalinkPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class LavalinkPlayer : ILavalinkPlayer, ILavalinkPlayerListener
private volatile ITrackQueueItem? _currentItem;
private volatile ITrackQueueItem? _replacedItem;
private volatile ITrackQueueItem? _nextItem;
private volatile string? _nextOverridenPlayableItemIdentifier;
private UpDownCounter<int>? _previousStateCounter;
private string? _previousVoiceServer;

Expand Down Expand Up @@ -218,9 +219,10 @@ ValueTask ILavalinkPlayerListener.NotifyTrackStartedAsync(LavalinkTrack track, C
ArgumentNullException.ThrowIfNull(track);

var nextTrack = Interlocked.Exchange(ref _nextItem, null) ?? CurrentItem;
Debug.Assert(track.Identifier == nextTrack?.Identifier);
var nextTrackIdentifier = Interlocked.Exchange(ref _nextOverridenPlayableItemIdentifier, null) ?? nextTrack?.Identifier;
Debug.Assert(track.Identifier == nextTrackIdentifier);

CurrentItem = track.Identifier == nextTrack?.Identifier
CurrentItem = track.Identifier == nextTrackIdentifier
? nextTrack
: new TrackQueueItem(new TrackReference(track));

Expand Down Expand Up @@ -265,7 +267,7 @@ public virtual async ValueTask PlayAsync(ITrackQueueItem trackQueueItem, TrackPl
.GetPlayableTrackAsync(cancellationToken)
.ConfigureAwait(false);

updateProperties.TrackData = playableTrack.ToString();
updateProperties.TrackData = _nextOverridenPlayableItemIdentifier = playableTrack.ToString();
}
else
{
Expand Down

0 comments on commit ce1543b

Please sign in to comment.