Skip to content

Commit

Permalink
Fix "Adding a playlist via 'QueuedLavalinkPlayerExtensions' does not …
Browse files Browse the repository at this point in the history
…work" (#188)

* Remove null propagation from queued extensions

* Add documentation
  • Loading branch information
NycroV authored Oct 13, 2024
1 parent b8e7622 commit fc7e926
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Lavalink4NET/Extensions/QueuedLavalinkPlayerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@

public static class QueuedLavalinkPlayerExtensions
{
/// <summary>
/// Adds a <see cref="TrackLoadResult"/> to the player's queue.<br/>
/// Returns the index of the track in the queue (or the last track added to the queue if <paramref name="loadResult"/> is a playlist)
/// </summary>
/// <param name="player">The player to enqueue the load result to.</param>
/// <param name="loadResult">The load result you want to enqueue.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The index of the track in the queue (or the last track added to the queue if <paramref name="loadResult"/> is a playlist)</returns>
/// <exception cref="InvalidOperationException">When the <paramref name="loadResult"/> contains no tracks.</exception>
public static async ValueTask<int> PlayAsync(this IQueuedLavalinkPlayer player, TrackLoadResult loadResult, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();

var queueOffset = default(int?);
int? queueOffset = default;

if (loadResult.Playlist is null)
{
// Single track
queueOffset ??= await player
queueOffset = await player
.PlayAsync(loadResult.Track!, cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
Expand All @@ -26,7 +35,7 @@ public static async ValueTask<int> PlayAsync(this IQueuedLavalinkPlayer player,
// Playlist
foreach (var track in loadResult.Tracks)
{
queueOffset ??= await player
queueOffset = await player
.PlayAsync(track, cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
Expand Down

0 comments on commit fc7e926

Please sign in to comment.