Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a playlist via "QueuedLavalinkPlayerExtensions" does not work #185

Closed
555KIV opened this issue Sep 12, 2024 · 0 comments · Fixed by #188
Closed

Adding a playlist via "QueuedLavalinkPlayerExtensions" does not work #185

555KIV opened this issue Sep 12, 2024 · 0 comments · Fixed by #188
Labels
bug Something isn't working

Comments

@555KIV
Copy link

555KIV commented Sep 12, 2024

When calling the PlayAsync method with a passed playlist of the TrackLoadResult type from this Extension, tracks from the playlist other than the first one are not added to Lavalink

The reason is most likely this:

When the first track is added to Lavalink, the PlayAsync method will return 0 and queueOffset will not be null. Then in the second iteration, the operator ??= will see that the left operand of queueOffset is not null, and accordingly discards the right operand without calling the method

The source file: https://github.com/angelobreuer/Lavalink4NET/blob/dev/src/Lavalink4NET/Extensions/QueuedLavalinkPlayerExtensions.cs#L29

public static async ValueTask<int> PlayAsync(this IQueuedLavalinkPlayer player, TrackLoadResult loadResult, CancellationToken cancellationToken = default)
    {
        cancellationToken.ThrowIfCancellationRequested();

        var queueOffset = default(int?);

        if (loadResult.Playlist is null)
        {
           
            queueOffset ??= await player 
              .PlayAsync(loadResult.Track!, cancellationToken: cancellationToken)
              .ConfigureAwait(false);
        }
        else
        {
            foreach (var track in loadResult.Tracks)
            {
               // There's a problem here
                queueOffset ??= await player
                  .PlayAsync(track, cancellationToken: cancellationToken)
                  .ConfigureAwait(false);
            }
        }

        return queueOffset ?? throw new InvalidOperationException("No track is present.");
    }
@NycroV NycroV mentioned this issue Sep 23, 2024
@NycroV NycroV linked a pull request Sep 23, 2024 that will close this issue
@NycroV NycroV removed a link to a pull request Sep 23, 2024
@NycroV NycroV added the bug Something isn't working label Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants